diff options
author | Arno <arno@disconnect.de> | 2018-02-03 08:02:05 +0100 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2018-02-03 08:02:05 +0100 |
commit | 8512ed1a06888a98f71367f4ac3da3f6edc945c3 (patch) | |
tree | cd9504d630e25ab1e1db9cb64c01d73dc6877d81 /configurationwidget.cpp | |
parent | cbb1974ae94858b101ba1bf92047236dcfa2e5fa (diff) | |
download | ShemovCleaner-8512ed1a06888a98f71367f4ac3da3f6edc945c3.tar.gz ShemovCleaner-8512ed1a06888a98f71367f4ac3da3f6edc945c3.tar.bz2 ShemovCleaner-8512ed1a06888a98f71367f4ac3da3f6edc945c3.zip |
Implement alternating row colors
Once again, surprisingly difficult, as you can see on the number of
changed files.
Coding the configuration options wasn't that difficult, but actually
using them was. As it turned out, the default style on Windows doesn't
use QApplication::palette() at all, though it does honor
setAlternatingRowColors(). It just doesn't use the palette colors, but
style sheets. Took me a while to figure out.
So, there's always another layer of indirection: First, add all
QTreeViews to Globals::views, then create a helper to set the style
sheet.
Diffstat (limited to 'configurationwidget.cpp')
-rw-r--r-- | configurationwidget.cpp | 61 |
1 files changed, 60 insertions, 1 deletions
diff --git a/configurationwidget.cpp b/configurationwidget.cpp index 33e1271..43188e6 100644 --- a/configurationwidget.cpp +++ b/configurationwidget.cpp @@ -7,11 +7,13 @@ #include <QVBoxLayout> #include <QLineEdit> #include <QFileDialog> +#include <QCheckBox> +#include <QColorDialog> #include "configurationwidget.h" #include "itemselectionwidget.h" -ConfigurationWidget::ConfigurationWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f) { +ConfigurationWidget::ConfigurationWidget(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f), mColors(2) { //database setup QGridLayout *dbLayout = new QGridLayout; mDbHost = new QLineEdit; @@ -64,6 +66,38 @@ ConfigurationWidget::ConfigurationWidget(QWidget *parent, Qt::WindowFlags f) : Q //mime type filters mMimeTypeW = new ItemSelectionWidget(ItemSelectionWidget::Item, tr("Mime Type Regex")); + //colors + QLabel *baseColorT = new QLabel(tr("Base color")); + mBaseColorL = new QLabel; + mBaseColorL->setFrameStyle(QFrame::Sunken | QFrame::Panel); + mBaseColorL->setScaledContents(true); + QPushButton *baseColorB = new QPushButton(tr("Choose...")); + baseColorB->setDisabled(true); + connect(baseColorB, &QPushButton::clicked, [=] { chooseColor(mBaseColorL, 0); }); + QLabel *altColorT = new QLabel(tr("Alternate color")); + mAltColorL = new QLabel; + mAltColorL->setFrameStyle(QFrame::Sunken | QFrame::Panel); + mAltColorL->setScaledContents(true); + QPushButton *altColorB = new QPushButton(tr("Choose...")); + altColorB->setDisabled(true); + connect(altColorB, &QPushButton::clicked, [=] { chooseColor(mAltColorL, 1); }); + mUseAltColors = new QCheckBox(tr("Use alternating colors")); + connect(mUseAltColors, &QCheckBox::stateChanged, [=]{ + baseColorB->setEnabled(mUseAltColors->isChecked()); + altColorB->setEnabled(mUseAltColors->isChecked()); + }); + QGridLayout *colorGrid = new QGridLayout; + colorGrid->setAlignment(Qt::AlignTop); + colorGrid->addWidget(baseColorT, 0, 0); + colorGrid->addWidget(mBaseColorL, 0, 1); + colorGrid->addWidget(baseColorB, 0, 2); + colorGrid->addWidget(altColorT, 1, 0); + colorGrid->addWidget(mAltColorL, 1, 1); + colorGrid->addWidget(altColorB, 1, 2); + colorGrid->addWidget(mUseAltColors, 2, 0, 1, 3, Qt::AlignHCenter); + QWidget *colorW = new QWidget; + colorW->setLayout(colorGrid); + //buttons QPushButton *acceptB = new QPushButton(tr("Save")); connect(acceptB, &QPushButton::clicked, this, &ConfigurationWidget::accept); @@ -83,6 +117,7 @@ ConfigurationWidget::ConfigurationWidget(QWidget *parent, Qt::WindowFlags f) : Q tab->addTab(mCopyDirW, tr("Copy dirs")); tab->addTab(mFavDirW, tr("Fav. dirs")); tab->addTab(mMimeTypeW, tr("MIME filter")); + tab->addTab(colorW, tr("Colors")); mainLayout->addWidget(tab); mainLayout->addLayout(bLayout); readSettings(); @@ -106,6 +141,9 @@ void ConfigurationWidget::accept(){ s.setValue("favdirs", favDirs); QStringList mimeFilters = mMimeTypeW->items(); s.setValue("mimefilters", mimeFilters); + s.setValue("alternatecolors", mUseAltColors->isChecked()); + s.setValue("basecolor", mColors.at(0)); + s.setValue("altcolor", mColors.at(1)); QDialog::accept(); } @@ -130,4 +168,25 @@ void ConfigurationWidget::readSettings(){ mFavDirW->setItems(favDirs); QStringList mimeFilters = s.value("mimefilters").toStringList(); mMimeTypeW->setItems(mimeFilters); + mUseAltColors->setChecked(s.value("alternatecolors").toBool()); + QVariant c1 = s.value("basecolor"); + mColors[0] = c1.value<QColor>(); + QPixmap pm1(mBaseColorL->sizeHint()); + pm1.fill(mColors.at(0)); + mBaseColorL->setPixmap(pm1); + QVariant c2 = s.value("altcolor"); + mColors[1] = c2.value<QColor>(); + QPixmap pm2(mAltColorL->sizeHint()); + pm2.fill(mColors.at(1)); + mAltColorL->setPixmap(pm2); +} + +void ConfigurationWidget::chooseColor(QLabel *l, int colorIndex){ + QColor c = QColorDialog::getColor(mColors.at(colorIndex), this); + if(c.isValid()){ + mColors[colorIndex] = c; + QPixmap pm(l->sizeHint()); + pm.fill(c); + l->setPixmap(pm); + } } |