15 * along with this program; if not, write to the Free Software |
15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
17 */ |
17 */ |
18 |
18 |
19 #include <QDialog> |
19 #include <QDialog> |
20 #include <QVBoxLayout> |
20 #include <QGridLayout> |
|
21 #include <QHBoxLayout> |
21 #include <QScrollArea> |
22 #include <QScrollArea> |
22 #include <QPushButton> |
23 #include <QPushButton> |
23 #include <QToolButton> |
24 #include <QToolButton> |
24 #include <QWidgetItem> |
25 #include <QWidgetItem> |
25 #include <QModelIndex> |
26 #include <QModelIndex> |
|
27 #include <QListView> |
|
28 #include <QLineEdit> |
26 #include <QLabel> |
29 #include <QLabel> |
|
30 #include <QSortFilterProxyModel> |
|
31 #include <QDebug> |
27 |
32 |
28 #include "flowlayout.h" |
|
29 #include "DataManager.h" |
33 #include "DataManager.h" |
|
34 #include "lineeditcursor.h" |
30 #include "ThemeModel.h" |
35 #include "ThemeModel.h" |
31 #include "themeprompt.h" |
36 #include "themeprompt.h" |
32 |
37 |
33 ThemePrompt::ThemePrompt(QWidget* parent) : QDialog(parent) |
38 |
|
39 void ThemeListView::moveUp() |
|
40 { |
|
41 setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier)); |
|
42 } |
|
43 |
|
44 void ThemeListView::moveDown() |
|
45 { |
|
46 setCurrentIndex(moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier)); |
|
47 } |
|
48 |
|
49 void ThemeListView::moveLeft() |
|
50 { |
|
51 setCurrentIndex(moveCursor(QAbstractItemView::MoveLeft, Qt::NoModifier)); |
|
52 } |
|
53 |
|
54 void ThemeListView::moveRight() |
|
55 { |
|
56 setCurrentIndex(moveCursor(QAbstractItemView::MoveRight, Qt::NoModifier)); |
|
57 } |
|
58 |
|
59 ThemePrompt::ThemePrompt(int currentIndex, QWidget* parent) : QDialog(parent) |
34 { |
60 { |
35 setModal(true); |
61 setModal(true); |
36 setWindowFlags(Qt::Sheet); |
62 setWindowFlags(Qt::Sheet); |
37 setWindowModality(Qt::WindowModal); |
63 setWindowModality(Qt::WindowModal); |
38 setMinimumSize(550, 430); |
64 setMinimumSize(550, 430); |
39 resize(550, 430); |
65 resize(550, 430); |
40 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
66 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
41 |
67 |
|
68 setStyleSheet("QPushButton { padding: 5px; margin-top: 10px; }"); |
|
69 |
|
70 // Theme model, and a model for setting a filter |
|
71 ThemeModel * themeModel = DataManager::instance().themeModel(); |
|
72 filterModel = new QSortFilterProxyModel(); |
|
73 filterModel->setSourceModel(themeModel); |
|
74 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); |
|
75 |
42 // Grid |
76 // Grid |
43 QVBoxLayout * dialogLayout = new QVBoxLayout(this); |
77 QGridLayout * dialogLayout = new QGridLayout(this); |
44 dialogLayout->setSpacing(0); |
78 dialogLayout->setSpacing(0); |
|
79 dialogLayout->setColumnStretch(1, 1); |
|
80 |
|
81 QHBoxLayout * topLayout = new QHBoxLayout(); |
45 |
82 |
46 // Help/prompt message at top |
83 // Help/prompt message at top |
47 QLabel * lblDesc = new QLabel(tr("Select a theme for this map")); |
84 QLabel * lblDesc = new QLabel(tr("Search for a theme:")); |
48 lblDesc->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: auto 20px;"); |
85 lblDesc->setObjectName("lblDesc"); |
|
86 lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); |
49 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
87 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
50 lblDesc->setFixedHeight(24); |
88 lblDesc->setFixedHeight(24); |
51 lblDesc->setMinimumWidth(0); |
89 lblDesc->setMinimumWidth(0); |
52 |
90 |
53 // Scroll area and container for theme icons |
91 // Filter text box |
54 QWidget * themesContainer = new QWidget(); |
92 QWidget * filterContainer = new QWidget(); |
55 FlowLayout * themesGrid = new FlowLayout(); |
93 filterContainer->setFixedHeight(24); |
56 themesContainer->setLayout(themesGrid); |
94 filterContainer->setObjectName("filterContainer"); |
57 QScrollArea * scrollArea = new QScrollArea(); |
95 filterContainer->setStyleSheet("#filterContainer { background: #F6CB1C; border-top-right-radius: 10px; padding: 3px; }"); |
58 scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
96 filterContainer->setFixedWidth(150); |
59 scrollArea->setObjectName("scrollArea"); |
97 txtFilter = new LineEditCursor(filterContainer); |
60 scrollArea->setStyleSheet("QScrollBar, #scrollArea { background-color: #130F2A; } #scrollArea { border-color: #F6CB1C; border-width: 3px; border-top-width: 0; border-style: solid; border-bottom-left-radius: 10px; border-bottom-right-radius: 10px; }"); |
98 txtFilter->setFixedWidth(150); |
61 scrollArea->setWidgetResizable(true); |
99 txtFilter->setFocus(); |
62 scrollArea->setFrameShape(QFrame::NoFrame); |
100 txtFilter->setFixedHeight(22); |
63 scrollArea->setWidget(themesContainer); |
101 txtFilter->setStyleSheet("LineEditCursor { border-width: 0px; border-radius: 6px; margin-top: 3px; margin-right: 3px; padding-left: 4px; padding-bottom: 2px; background-color: rgb(23, 11, 54); } LineEditCursor:hover, LineEditCursor:focus { background-color: rgb(13, 5, 68); }"); |
|
102 connect(txtFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged(const QString &))); |
|
103 connect(txtFilter, SIGNAL(moveUp()), this, SLOT(moveUp())); |
|
104 connect(txtFilter, SIGNAL(moveDown()), this, SLOT(moveDown())); |
|
105 connect(txtFilter, SIGNAL(moveLeft()), this, SLOT(moveLeft())); |
|
106 connect(txtFilter, SIGNAL(moveRight()), this, SLOT(moveRight())); |
|
107 |
|
108 // Corner widget |
|
109 QLabel * corner = new QLabel(); |
|
110 corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png"))); |
|
111 corner->setFixedSize(10, 10); |
|
112 |
|
113 // Add widgets to top layout |
|
114 topLayout->addWidget(lblDesc); |
|
115 topLayout->addWidget(filterContainer); |
|
116 topLayout->addWidget(corner, 0, Qt::AlignBottom); |
|
117 topLayout->addStretch(1); |
64 |
118 |
65 // Cancel button (closes dialog) |
119 // Cancel button (closes dialog) |
66 QPushButton * btnCancel = new QPushButton(tr("Cancel")); |
120 QPushButton * btnCancel = new QPushButton(tr("Cancel")); |
67 btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;"); |
|
68 connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
121 connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); |
69 |
122 |
|
123 // Select button |
|
124 QPushButton * btnSelect = new QPushButton(tr("Use selected theme")); |
|
125 btnSelect->setDefault(true); |
|
126 connect(btnSelect, SIGNAL(clicked()), this, SLOT(onAccepted())); |
|
127 |
|
128 // Add themes |
|
129 list = new ThemeListView(); |
|
130 list->setModel(filterModel); |
|
131 list->setViewMode(QListView::IconMode); |
|
132 list->setResizeMode(QListView::Adjust); |
|
133 list->setMovement(QListView::Static); |
|
134 list->setEditTriggers(QAbstractItemView::NoEditTriggers); |
|
135 list->setSpacing(8); |
|
136 list->setWordWrap(true); |
|
137 list->setSelectionMode(QAbstractItemView::SingleSelection); |
|
138 list->setObjectName("themeList"); |
|
139 list->setCurrentIndex(filterModel->index(currentIndex, 0)); |
|
140 connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(themeChosen(const QModelIndex &))); |
|
141 connect(list, SIGNAL(clicked(const QModelIndex &)), this, SLOT(themeChosen(const QModelIndex &))); |
|
142 |
70 // Add elements to layouts |
143 // Add elements to layouts |
71 dialogLayout->addWidget(lblDesc, 0); |
144 dialogLayout->addLayout(topLayout, 0, 0, 1, 3); |
72 dialogLayout->addWidget(scrollArea, 1); |
145 dialogLayout->addWidget(list, 1, 0, 1, 3); |
73 dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft); |
146 dialogLayout->addWidget(btnCancel, 2, 0, 1, 1, Qt::AlignLeft); |
|
147 dialogLayout->addWidget(btnSelect, 2, 2, 1, 1, Qt::AlignRight); |
|
148 } |
74 |
149 |
75 // Tooltip label for theme name |
150 void ThemePrompt::moveUp() |
76 lblToolTip = new QLabel(this); |
151 { |
|
152 list->moveUp(); |
|
153 } |
77 |
154 |
78 // Add theme buttons |
155 void ThemePrompt::moveDown() |
79 ThemeModel * themes = DataManager::instance().themeModel(); |
156 { |
80 for (int i = 0; i < themes->rowCount(); i++) |
157 list->moveDown(); |
81 { |
158 } |
82 QModelIndex index = themes->index(i, 0); |
159 |
83 QToolButton * btn = new QToolButton(); |
160 void ThemePrompt::moveLeft() |
84 bool dlc = themes->data(index, Qt::UserRole + 2).toBool(); |
161 { |
85 btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); |
162 list->moveLeft(); |
86 btn->setIcon(qVariantValue<QIcon>(themes->data(index, Qt::UserRole))); |
163 } |
87 btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString()); |
164 |
88 btn->setIconSize(QSize(60, 60)); |
165 void ThemePrompt::moveRight() |
89 btn->setProperty("themeID", QVariant(i)); |
166 { |
90 btn->setStyleSheet("padding: 2px;"); |
167 list->moveRight(); |
91 connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked())); |
168 } |
92 themesGrid->addWidget(btn); |
169 |
93 } |
170 void ThemePrompt::onAccepted() |
|
171 { |
|
172 themeChosen(list->currentIndex()); |
94 } |
173 } |
95 |
174 |
96 // When a theme is selected |
175 // When a theme is selected |
97 void ThemePrompt::themeClicked() |
176 void ThemePrompt::themeChosen(const QModelIndex & index) |
98 { |
177 { |
99 QWidget * btn = (QWidget*)sender(); |
178 done(filterModel->mapToSource(index).row() + 1); // Since returning 0 means canceled |
100 done(btn->property("themeID").toInt() + 1); // Since returning 0 means canceled |
|
101 } |
179 } |
|
180 |
|
181 // When the text in the filter text box is changed |
|
182 void ThemePrompt::filterChanged(const QString & text) |
|
183 { |
|
184 filterModel->setFilterFixedString(text); |
|
185 list->setCurrentIndex(filterModel->index(0, 0)); |
|
186 } |