diff -r 555235e90010 -r f605bc59c603 QTfrontend/ui/widget/themeprompt.cpp --- a/QTfrontend/ui/widget/themeprompt.cpp Fri Feb 08 21:22:11 2013 -0500 +++ b/QTfrontend/ui/widget/themeprompt.cpp Sat Feb 09 15:26:10 2013 -0500 @@ -17,20 +17,26 @@ */ #include -#include +#include +#include #include #include #include #include #include +#include +#include #include +#include +#include +#include -#include "flowlayout.h" #include "DataManager.h" +#include "lineeditcursor.h" #include "ThemeModel.h" #include "themeprompt.h" -ThemePrompt::ThemePrompt(QWidget* parent) : QDialog(parent) +ThemePrompt::ThemePrompt(int currentIndex, QWidget* parent) : QDialog(parent) { setModal(true); setWindowFlags(Qt::Sheet); @@ -39,63 +45,128 @@ resize(550, 430); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + setStyleSheet("QPushButton { padding: 5px; margin-top: 10px; }"); + + // Theme model, and a model for setting a filter + ThemeModel * themeModel = DataManager::instance().themeModel(); + filterModel = new QSortFilterProxyModel(); + filterModel->setSourceModel(themeModel); + filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + // Grid - QVBoxLayout * dialogLayout = new QVBoxLayout(this); + QGridLayout * dialogLayout = new QGridLayout(this); dialogLayout->setSpacing(0); + dialogLayout->setColumnStretch(1, 1); + + QHBoxLayout * topLayout = new QHBoxLayout(); // Help/prompt message at top - QLabel * lblDesc = new QLabel(tr("Select a theme for this map")); - lblDesc->setStyleSheet("color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; border-top-right-radius: 10px; padding: auto 20px;"); + QLabel * lblDesc = new QLabel(tr("Select a theme")); + lblDesc->setObjectName("lblDesc"); + lblDesc->setStyleSheet("#lblDesc { color: #130F2A; background: #F6CB1C; border: solid 4px #F6CB1C; border-top-left-radius: 10px; padding: 4px 10px;}"); lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); lblDesc->setFixedHeight(24); lblDesc->setMinimumWidth(0); - // Scroll area and container for theme icons - QWidget * themesContainer = new QWidget(); - FlowLayout * themesGrid = new FlowLayout(); - themesContainer->setLayout(themesGrid); - QScrollArea * scrollArea = new QScrollArea(); - scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); - scrollArea->setObjectName("scrollArea"); - 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; }"); - scrollArea->setWidgetResizable(true); - scrollArea->setFrameShape(QFrame::NoFrame); - scrollArea->setWidget(themesContainer); + // Filter text box + QWidget * filterContainer = new QWidget(); + filterContainer->setFixedHeight(24); + filterContainer->setObjectName("filterContainer"); + filterContainer->setStyleSheet("#filterContainer { background: #F6CB1C; border-top-right-radius: 10px; padding: 3px; }"); + filterContainer->setFixedWidth(250); + txtFilter = new LineEditCursor(filterContainer); + txtFilter->setFixedWidth(250); + txtFilter->setFocus(); + txtFilter->setFixedHeight(22); + connect(txtFilter, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged(const QString &))); + connect(txtFilter, SIGNAL(moveUp()), this, SLOT(moveUp())); + connect(txtFilter, SIGNAL(moveDown()), this, SLOT(moveDown())); + connect(txtFilter, SIGNAL(moveLeft()), this, SLOT(moveLeft())); + connect(txtFilter, SIGNAL(moveRight()), this, SLOT(moveRight())); + + // Filter label + QLabel * lblFilter = new QLabel(tr("Filter: "), txtFilter); + QFontMetrics lblMetrics(lblFilter->font()); + int lblFilterWidth = lblMetrics.width(lblFilter->text()); + lblFilter->setStyleSheet(QString("background: none; margin-left: -%1px; margin-top: 4px;").arg(lblFilterWidth + 5)); + txtFilter->setStyleSheet(QString("LineEditCursor, QLabel { border-width: 0px; border-radius: 6px; margin-top: 3px; margin-right: 3px; padding-left: %1px; padding-bottom: 2px; background-color: rgb(23, 11, 54); } LineEditCursor:hover, LineEditCursor:focus { background-color: rgb(13, 5, 68); }").arg(lblFilterWidth + 5)); + + // Corner widget + QLabel * corner = new QLabel(); + corner->setPixmap(QPixmap(QString::fromUtf8(":/res/inverse-corner-bl.png"))); + corner->setFixedSize(10, 10); + + // Add widgets to top layout + topLayout->addWidget(lblDesc); + topLayout->addWidget(filterContainer); + topLayout->addWidget(corner, 0, Qt::AlignBottom); + topLayout->addStretch(1); // Cancel button (closes dialog) QPushButton * btnCancel = new QPushButton(tr("Cancel")); - btnCancel->setStyleSheet("padding: 5px; margin-top: 10px;"); connect(btnCancel, SIGNAL(clicked()), this, SLOT(reject())); + // Select button + QPushButton * btnSelect = new QPushButton(tr("Use selected theme")); + btnSelect->setDefault(true); + connect(btnSelect, SIGNAL(clicked()), this, SLOT(onAccepted())); + + // Add themes + list = new ThemeListView(); + list->setModel(filterModel); + list->setViewMode(QListView::IconMode); + list->setResizeMode(QListView::Adjust); + list->setMovement(QListView::Static); + list->setEditTriggers(QAbstractItemView::NoEditTriggers); + list->setSpacing(8); + list->setWordWrap(true); + list->setSelectionMode(QAbstractItemView::SingleSelection); + list->setObjectName("themeList"); + list->setCurrentIndex(filterModel->index(currentIndex, 0)); + connect(list, SIGNAL(activated(const QModelIndex &)), this, SLOT(themeChosen(const QModelIndex &))); + connect(list, SIGNAL(clicked(const QModelIndex &)), this, SLOT(themeChosen(const QModelIndex &))); + // Add elements to layouts - dialogLayout->addWidget(lblDesc, 0); - dialogLayout->addWidget(scrollArea, 1); - dialogLayout->addWidget(btnCancel, 0, Qt::AlignLeft); + dialogLayout->addLayout(topLayout, 0, 0, 1, 3); + dialogLayout->addWidget(list, 1, 0, 1, 3); + dialogLayout->addWidget(btnCancel, 2, 0, 1, 1, Qt::AlignLeft); + dialogLayout->addWidget(btnSelect, 2, 2, 1, 1, Qt::AlignRight); +} - // Tooltip label for theme name - lblToolTip = new QLabel(this); +void ThemePrompt::moveUp() +{ + list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier)); +} - // Add theme buttons - ThemeModel * themes = DataManager::instance().themeModel(); - for (int i = 0; i < themes->rowCount(); i++) - { - QModelIndex index = themes->index(i, 0); - QToolButton * btn = new QToolButton(); - bool dlc = themes->data(index, Qt::UserRole + 2).toBool(); - btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); - btn->setIcon(qVariantValue(themes->data(index, Qt::UserRole))); - btn->setText((dlc ? "*" : "") + themes->data(index, Qt::DisplayRole).toString()); - btn->setIconSize(QSize(60, 60)); - btn->setProperty("themeID", QVariant(i)); - btn->setStyleSheet("padding: 2px;"); - connect(btn, SIGNAL(clicked()), this, SLOT(themeClicked())); - themesGrid->addWidget(btn); - } +void ThemePrompt::moveDown() +{ + list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier)); +} + +void ThemePrompt::moveLeft() +{ + list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveLeft, Qt::NoModifier)); +} + +void ThemePrompt::moveRight() +{ + list->setCurrentIndex(list->moveCursor(QAbstractItemView::MoveRight, Qt::NoModifier)); +} + +void ThemePrompt::onAccepted() +{ + themeChosen(list->currentIndex()); } // When a theme is selected -void ThemePrompt::themeClicked() +void ThemePrompt::themeChosen(const QModelIndex & index) { - QWidget * btn = (QWidget*)sender(); - done(btn->property("themeID").toInt() + 1); // Since returning 0 means canceled + done(filterModel->mapToSource(index).row() + 1); // Since returning 0 means canceled } + +// When the text in the filter text box is changed +void ThemePrompt::filterChanged(const QString & text) +{ + filterModel->setFilterFixedString(text); + list->setCurrentIndex(filterModel->index(0, 0)); +} \ No newline at end of file