1 /**********************************************************************
2  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; either version 2, or (at your option)
6    any later version.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 ***********************************************************************/
13 
14 #ifndef FC__PLRDLG_H
15 #define FC__PLRDLG_H
16 
17 #ifdef HAVE_CONFIG_H
18 #include <fc_config.h>
19 #endif
20 
21 extern "C" {
22 #include "plrdlg_g.h"
23 }
24 
25 //common
26 #include "colors.h"
27 #include "player.h"
28 #include "research.h"
29 
30 // gui-qt
31 #include "sprite.h"
32 
33 // Qt
34 #include <QAbstractListModel>
35 #include <QItemDelegate>
36 #include <QTreeView>
37 #include <QWidget>
38 
39 class QHBoxLayout;
40 class QLabel;
41 class QPushButton;
42 class QSortFilterProxyModel;
43 class QSplitter;
44 class QTableWidget;
45 class QVBoxLayout;
46 class plr_report;
47 
48 /***************************************************************************
49   Item delegate for painting in model of nations view table
50 ***************************************************************************/
51 class plr_item_delegate:public QItemDelegate {
52   Q_OBJECT
53 
54 public:
plr_item_delegate(QObject * parent)55  plr_item_delegate(QObject *parent) : QItemDelegate(parent) {}
~plr_item_delegate()56  ~plr_item_delegate() {}
57  void paint(QPainter *painter, const QStyleOptionViewItem &option,
58             const QModelIndex &index) const;
59  virtual QSize sizeHint (const QStyleOptionViewItem & option,
60                          const QModelIndex & index ) const;
61 };
62 
63 /***************************************************************************
64   Single item in model of nations view table
65 ***************************************************************************/
66 class plr_item: public QObject {
67 Q_OBJECT
68 
69 public:
70   plr_item(struct player *pplayer);
columnCount()71   inline int columnCount() const { return num_player_dlg_columns; }
72   QVariant data(int column, int role = Qt::DisplayRole) const;
73   bool setData(int column, const QVariant &value, int role = Qt::DisplayRole);
74 private:
75   struct player *ipplayer;
76 };
77 
78 /***************************************************************************
79   Nation/Player model
80 ***************************************************************************/
81 class plr_model : public QAbstractListModel
82 {
83   Q_OBJECT
84 public:
85   plr_model(QObject *parent = 0);
86   ~plr_model();
87   inline int rowCount(const QModelIndex &index = QModelIndex()) const {
88     Q_UNUSED(index);
89     return plr_list.size();
90   }
91   int columnCount(const QModelIndex &parent = QModelIndex()) const {
92     Q_UNUSED(parent);
93     return num_player_dlg_columns;
94   }
95   QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
96   bool setData(const QModelIndex &index, const QVariant &value,
97                int role = Qt::DisplayRole);
98   QVariant headerData(int section, Qt::Orientation orientation,
99                       int role) const;
100   QVariant hide_data(int section) const;
101   void populate();
102 private slots:
103   void notify_plr_changed(int row);
104 private:
105   QList<plr_item *> plr_list;
106 };
107 
108 /***************************************************************************
109   Player widget to show player/nation model
110 ***************************************************************************/
111 class plr_widget: public QTreeView
112 {
113   Q_OBJECT
114   plr_model *list_model;
115   QSortFilterProxyModel *filter_model;
116   plr_item_delegate *pid;
117   plr_report *plr;
118   QString techs_known;
119   QString techs_unknown;
120   struct player *selected_player;
121 public:
122   plr_widget(plr_report *pr);
123   ~plr_widget();
124   void restore_selection();
125   plr_model *get_model() const;
126   QString intel_str;
127   QString ally_str;
128   QString tech_str;
129   struct player *other_player;
130 public slots:
131   void display_header_menu(const QPoint &);
132   void nation_selected(const QItemSelection &sl, const QItemSelection &ds);
133 private:
134   void mousePressEvent(QMouseEvent *event);
135   void hide_columns();
136 };
137 
138 /***************************************************************************
139   Widget to show as tab widget in players view.
140 ***************************************************************************/
141 class plr_report: public QWidget
142 {
143   Q_OBJECT
144   plr_widget *plr_wdg;
145   QLabel *plr_label;
146   QLabel *ally_label;
147   QLabel *tech_label;
148   QSplitter *v_splitter;
149   QSplitter *h_splitter;
150   QPushButton *meet_but;
151   QPushButton *cancel_but;
152   QPushButton *withdraw_but;
153   QPushButton *toggle_ai_but;
154   QVBoxLayout *layout;
155   QHBoxLayout *hlayout;
156 public:
157   plr_report();
158   ~plr_report();
159   void update_report(bool update_selection = true);
160   void init();
161   void call_meeting();
162 private:
163   struct player *other_player;
164   int index;
165 private slots:
166   void req_meeeting();
167   void req_caancel_threaty(); /** somehow autoconnect feature messes
168                                *  here and names are bit odd to cheat
169                                *  autoconnect */
170   void req_wiithdrw_vision();
171   void toggle_ai_mode();
172 };
173 
174 void popup_players_dialog(bool raise);
175 void popdown_players_report(void);
176 
177 
178 #endif /* FC__PLRDLG_H */
179