void ItemTagsLoader::addTagToSettingsTable(const ItemTagsLoader::Tag &tag) { QTableWidget *t = ui->tableWidget; const int row = t->rowCount(); t->insertRow(row); t->setItem( row, tagsTableColumns::name, new TagTableWidgetItem(tag.name) ); t->setItem( row, tagsTableColumns::match, new QTableWidgetItem(tag.match) ); t->setItem( row, tagsTableColumns::styleSheet, new QTableWidgetItem(tag.styleSheet) ); t->setItem( row, tagsTableColumns::color, new QTableWidgetItem() ); t->setItem( row, tagsTableColumns::icon, new QTableWidgetItem() ); auto colorButton = new QPushButton(t); const QColor color = tag.color.isEmpty() ? QColor::fromRgb(50, 50, 50) : deserializeColor(tag.color); setColorIcon(colorButton, color); t->setCellWidget(row, tagsTableColumns::color, colorButton); connect(colorButton, &QAbstractButton::clicked, this, &ItemTagsLoader::onColorButtonClicked); auto iconButton = new IconSelectButton(t); iconButton->setCurrentIcon(tag.icon); t->setCellWidget(row, tagsTableColumns::icon, iconButton); connect(iconButton, &IconSelectButton::currentIconChanged, this, &ItemTagsLoader::onAllTableWidgetItemsChanged); onTableWidgetItemChanged(t->item(row, 0)); }
void IconSelectButton::onClicked() { QScopedPointer<IconSelectDialog> dialog( new IconSelectDialog(m_currentIcon, this) ); dialog->setAttribute(Qt::WA_DeleteOnClose, true); connect(dialog.data(), SIGNAL(iconSelected(QString)), this, SLOT(setCurrentIcon(QString))); dialog->open(); dialog.take(); }
IconSelectButton::IconSelectButton(QWidget *parent) : QPushButton(parent) , m_currentIcon() { setToolTip(tr("Select Icon...")); connect( this, &QAbstractButton::clicked, this, &IconSelectButton::onClicked ); // reset button text to "..." m_currentIcon = "X"; setCurrentIcon(QString()); }
IconSelectButton::IconSelectButton(QWidget *parent) : QPushButton(parent) , m_currentIcon() { setToolTip(tr("Select Icon...")); connect( this, SIGNAL(clicked()), SLOT(onClicked()) ); // reset button text to "..." m_currentIcon = "X"; setCurrentIcon(QString()); }
QWidget *ItemSyncLoader::createSettingsWidget(QWidget *parent) { ui.reset(new Ui::ItemSyncSettings); QWidget *w = new QWidget(parent); ui->setupUi(w); // Init tab sync path table. const QStringList tabPaths = m_settings.value(configSyncTabs).toStringList(); QTableWidget *t = ui->tableWidgetSyncTabs; for (int row = 0, i = 0; i < tabPaths.size() + 20; ++row, i += 2) { t->insertRow(row); t->setItem( row, syncTabsTableColumns::tabName, new QTableWidgetItem(tabPaths.value(i)) ); t->setItem( row, syncTabsTableColumns::path, new QTableWidgetItem(tabPaths.value(i + 1)) ); QPushButton *button = createBrowseButton(); t->setCellWidget(row, syncTabsTableColumns::browse, button); connect( button, &QAbstractButton::clicked, this, &ItemSyncLoader::onBrowseButtonClicked ); } setNormalStretchFixedColumns(t, syncTabsTableColumns::tabName, syncTabsTableColumns::path, syncTabsTableColumns::browse); // Init file format table. const QVariantList formatSettings = m_settings.value(configFormatSettings).toList(); t = ui->tableWidgetFormatSettings; for (int row = 0; row < formatSettings.size() + 10; ++row) { const QVariantMap format = formatSettings.value(row).toMap(); const QString formats = format.value("formats").toStringList().join(", "); t->insertRow(row); t->setItem( row, formatSettingsTableColumns::formats, new QTableWidgetItem(formats) ); t->setItem( row, formatSettingsTableColumns::itemMime, new QTableWidgetItem(format.value("itemMime").toString()) ); auto button = new IconSelectButton(); button->setCurrentIcon( format.value("icon").toString() ); t->setCellWidget(row, formatSettingsTableColumns::icon, button); } setNormalStretchFixedColumns(t, formatSettingsTableColumns::formats, formatSettingsTableColumns::itemMime, formatSettingsTableColumns::icon); return w; }