diff --git a/src/gui/preferences/settingsabstractwidget.cpp b/src/gui/preferences/settingsabstractwidget.cpp index 53690fa8..901f38c5 100644 --- a/src/gui/preferences/settingsabstractwidget.cpp +++ b/src/gui/preferences/settingsabstractwidget.cpp @@ -1,24 +1,24 @@ /*************************************************************************** - * Copyright (C) 2004-2014 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsabstractwidget.h" SettingsAbstractWidget::SettingsAbstractWidget(QWidget *parent) : QWidget(parent) { /// nothing } diff --git a/src/gui/preferences/settingsabstractwidget.h b/src/gui/preferences/settingsabstractwidget.h index 4b01ba0c..83549759 100644 --- a/src/gui/preferences/settingsabstractwidget.h +++ b/src/gui/preferences/settingsabstractwidget.h @@ -1,50 +1,55 @@ /*************************************************************************** - * Copyright (C) 2004-2014 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSABSTRACTWIDGET_H #define KBIBTEX_GUI_SETTINGSABSTRACTWIDGET_H #include #include #include #include "kbibtexgui_export.h" /** * @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsAbstractWidget : public QWidget { Q_OBJECT public: explicit SettingsAbstractWidget(QWidget *parent); // virtual ~SettingsAbstractWidget() { /* nothing */ }; virtual QString label() const = 0; virtual QIcon icon() const = 0; signals: void changed(); public slots: virtual void loadState() = 0; - virtual void saveState() = 0; + /** + * Save the state of this settings widget into the configuration settings, + * usually using the Preferences class. + * @return true if saved settings differed from previous values, false otherwise or under error conditions + */ + virtual bool saveState() = 0; virtual void resetToDefaults() = 0; }; #endif // KBIBTEX_GUI_SETTINGSABSTRACTWIDGET_H diff --git a/src/gui/preferences/settingscolorlabelwidget.cpp b/src/gui/preferences/settingscolorlabelwidget.cpp index 03d00798..744290f3 100644 --- a/src/gui/preferences/settingscolorlabelwidget.cpp +++ b/src/gui/preferences/settingscolorlabelwidget.cpp @@ -1,522 +1,532 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingscolorlabelwidget.h" #include "settingscolorlabelwidget_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "file/fileview.h" #include "field/colorlabelwidget.h" class ColorLabelSettingsDelegate : public QStyledItemDelegate { Q_OBJECT public: ColorLabelSettingsDelegate(QWidget *parent = nullptr) : QStyledItemDelegate(parent) { /// nothing } QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const override { if (index.column() == 0) /// Colors are to be edited in a color button return new KColorButton(parent); else /// Text strings are to be edited in a line edit return new QLineEdit(parent); } void setEditorData(QWidget *editor, const QModelIndex &index) const override { if (index.column() == 0) { KColorButton *colorButton = qobject_cast(editor); /// Initialized color button with row's current color colorButton->setColor(index.model()->data(index, Qt::EditRole).value()); } else { QLineEdit *lineEdit = qobject_cast(editor); /// Initialized line edit with row's current color's label lineEdit->setText(index.model()->data(index, Qt::EditRole).toString()); } } void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override { if (index.column() == 0) { KColorButton *colorButton = qobject_cast(editor); if (colorButton->color() != Qt::black) /// Assign color button's color back to model model->setData(index, colorButton->color(), Qt::EditRole); } else if (index.column() == 1) { QLineEdit *lineEdit = qobject_cast(editor); if (!lineEdit->text().isEmpty()) /// Assign line edit's text back to model model->setData(index, lineEdit->text(), Qt::EditRole); } } QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override { QSize hint = QStyledItemDelegate::sizeHint(option, index); QFontMetrics fm = QFontMetrics(QFont()); /// Enforce minimum height of 4 times x-height hint.setHeight(qMax(hint.height(), fm.xHeight() * 4)); return hint; } }; ColorLabelSettingsModel::ColorLabelSettingsModel(QObject *parent) : QAbstractItemModel(parent) { /// Load stored color-label pairs loadState(); } int ColorLabelSettingsModel::rowCount(const QModelIndex &parent) const { /// Single-level list of color-label pairs has as many rows as pairs return parent == QModelIndex() ? colorLabelPairs.size() : 0; } int ColorLabelSettingsModel::columnCount(const QModelIndex &parent) const { /// Single-level list of color-label pairs has as 2 columns /// (one of color, one for label) return parent == QModelIndex() ? 2 : 0; } QModelIndex ColorLabelSettingsModel::index(int row, int column, const QModelIndex &parent) const { if (row >= 0 && row <= colorLabelPairs.size() - 1 && column >= 0 && column <= 1 && parent == QModelIndex()) /// Create index for valid combinations of row, column, and parent return createIndex(row, column, row); else return QModelIndex(); } QModelIndex ColorLabelSettingsModel::parent(const QModelIndex &) const { /// Single-level list's indices have no other index as parent return QModelIndex(); } QVariant ColorLabelSettingsModel::data(const QModelIndex &index, int role) const { /// Skip invalid model indices if (index == QModelIndex() || index.row() < 0 || index.row() >= colorLabelPairs.size()) return QVariant(); if ((role == Qt::DecorationRole || role == Qt::EditRole) && index.column() == 0) /// First column has colors only (no text) return colorLabelPairs[index.row()].first; else if ((role == Qt::DisplayRole || role == Qt::EditRole) && index.column() == 1) /// Second column has colors' labels return colorLabelPairs[index.row()].second; return QVariant(); } bool ColorLabelSettingsModel::setData(const QModelIndex &index, const QVariant &value, int role) { if (role == Qt::EditRole) { const QModelIndex left = index.sibling(index.row(), 0); const QModelIndex right = index.sibling(index.row(), 1); if (index.column() == 0 && value.canConvert()) { /// For first column if a valid color is to be set ... const QColor color = value.value(); if (color != Qt::black && (color.red() > 0 || color.green() > 0 || color.blue() > 0)) { /// ... store this color in the data structure colorLabelPairs[index.row()].first = color; /// Notify everyone about the changes emit dataChanged(left, right); emit modified(); return true; } } else if (index.column() == 1 && value.canConvert()) { /// For second column if a label text is to be set ... const QString text = value.toString(); if (!text.isEmpty()) { /// ... store this text in the data structure colorLabelPairs[index.row()].second = text; /// Notify everyone about the changes emit dataChanged(left, right); emit modified(); return true; } } } return false; } Qt::ItemFlags ColorLabelSettingsModel::flags(const QModelIndex &index) const { Qt::ItemFlags result = QAbstractItemModel::flags(index); result |= Qt::ItemIsEditable; ///< all cells can be edited (color or text label) return result; } QVariant ColorLabelSettingsModel::headerData(int section, Qt::Orientation orientation, int role) const { /// Only vertical lists supported if (orientation != Qt::Horizontal || role != Qt::DisplayRole) return QVariant(); switch (section) { case 0: return i18n("Color"); case 1: return i18n("Label"); default: return QVariant(); } } /** * Load list of color-label pairs from user's configuration file. * Fall back on pre-defined colors and labels if no user settings exist. */ void ColorLabelSettingsModel::loadState() { colorLabelPairs = Preferences::instance().colorCodes(); } /** * Save list of color-label pairs in user's configuration file. */ -void ColorLabelSettingsModel::saveState() +bool ColorLabelSettingsModel::saveState() { + const QVector> oldColorCodes = Preferences::instance().colorCodes(); Preferences::instance().setColorCodes(colorLabelPairs); + + QVector>::ConstIterator itOld = oldColorCodes.constBegin(); + QVector>::ConstIterator itNew = colorLabelPairs.constBegin(); + for (; itOld != oldColorCodes.constEnd() && itNew != colorLabelPairs.constEnd(); ++itOld, ++itNew) + if (itOld->first != itNew->first || itOld->second != itNew->second) + return true; + return !(itOld == oldColorCodes.constEnd() && itNew == colorLabelPairs.constEnd()); } /** * Revert in-memory data structure (list of color-label pairs) to defaults. * Does not touch user's configuration file (would require an Apply operation). */ void ColorLabelSettingsModel::resetToDefaults() { colorLabelPairs = Preferences::instance().defaultColorCodes; emit modified(); } /** * Add a new color-label pair to this model. * The pair will be appended to the list's end. * No check is performed if a similar color or label is already in use. * * @param color Color of the color-label pair * @param label Label of the color-label pair */ void ColorLabelSettingsModel::addColorLabel(const QColor &color, const QString &label) { const int newRow = colorLabelPairs.size(); beginInsertRows(QModelIndex(), newRow, newRow); colorLabelPairs.append(qMakePair(color, label)); endInsertRows(); emit modified(); } /** * Remove a color-label pair from this model. * The pair is identified by the row number. * * @param row Row number of the pair to be removed */ void ColorLabelSettingsModel::removeColorLabel(int row) { if (row >= 0 && row < colorLabelPairs.size()) { beginRemoveRows(QModelIndex(), row, row); colorLabelPairs.removeAt(row); endRemoveRows(); emit modified(); } } class SettingsColorLabelWidget::Private { private: SettingsColorLabelWidget *p; ColorLabelSettingsDelegate *delegate; public: ColorLabelSettingsModel *model; QPushButton *buttonRemove; QTreeView *view; Private(SettingsColorLabelWidget *parent) : p(parent), delegate(nullptr), model(nullptr), buttonRemove(nullptr), view(nullptr) { /// nothing } void loadState() { /// Delegate state maintenance to model if (model != nullptr) model->loadState(); } - void saveState() { + bool saveState() { /// Delegate state maintenance to model if (model != nullptr) - model->saveState(); + return model->saveState(); + else + return false; } void resetToDefaults() { /// Delegate state maintenance to model if (model != nullptr) model->resetToDefaults(); } void setupGUI() { QGridLayout *layout = new QGridLayout(p); layout->setMargin(0); /// Central element in the main widget /// is a tree view for color-label pairs view = new QTreeView(p); layout->addWidget(view, 0, 0, 3, 1); view->setRootIsDecorated(false); /// Tree view's model maintains color-label pairs model = new ColorLabelSettingsModel(view); view->setModel(model); /// Changes in the model (e.g. through setData(..)) /// get propagated as this widget's changed() signal connect(model, &ColorLabelSettingsModel::modified, p, &SettingsColorLabelWidget::changed); /// Delegate to handle changes of color (through KColorButton) /// and label (throuh QLineEdit) delegate = new ColorLabelSettingsDelegate(view); view->setItemDelegate(delegate); /// Button to add a new randomized color QPushButton *buttonAdd = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add..."), p); layout->addWidget(buttonAdd, 0, 1, 1, 1); connect(buttonAdd, &QPushButton::clicked, p, &SettingsColorLabelWidget::addColor); /// Remove selected color-label pair; button is disabled /// if no row is selected in tree view buttonRemove = new QPushButton(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("Remove"), p); layout->addWidget(buttonRemove, 1, 1, 1, 1); buttonRemove->setEnabled(false); connect(buttonRemove, &QPushButton::clicked, p, &SettingsColorLabelWidget::removeColor); } }; SettingsColorLabelWidget::SettingsColorLabelWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new Private(this)) { /// Seed random number generator qsrand(time(nullptr)); /// Setup GUI elements d->setupGUI(); /// Connect signals connect(d->view->selectionModel(), &QItemSelectionModel::selectionChanged, this, &SettingsColorLabelWidget::updateRemoveButtonStatus); } SettingsColorLabelWidget::~SettingsColorLabelWidget() { delete d; } QString SettingsColorLabelWidget::label() const { return i18n("Color & Labels"); } QIcon SettingsColorLabelWidget::icon() const { return QIcon::fromTheme(QStringLiteral("preferences-desktop-color")); } void SettingsColorLabelWidget::loadState() { d->loadState(); } -void SettingsColorLabelWidget::saveState() +bool SettingsColorLabelWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsColorLabelWidget::resetToDefaults() { d->resetToDefaults(); } void SettingsColorLabelWidget::addColor() { /// Create a randomized color, but guarantee /// some minimum value for each color component const QColor newColor((qrand() & 0xff) | 0x30, (qrand() & 0xff) | 0x30, (qrand() & 0xff) | 0x30); /// Set the new label to be the color's hex string const QString newColorName(newColor.name().remove(QLatin1Char('#'))); /// Add new color-label pair to model's data d->model->addColorLabel(newColor, i18nc("Label for a new color; placeholder is for a 6-digit hex string", "NewColor%1", newColorName)); } void SettingsColorLabelWidget::removeColor() { if (!d->view->selectionModel()->selectedIndexes().isEmpty()) { /// Determine which row is selected const int row = d->view->selectionModel()->selectedIndexes().first().row(); /// Remove row from model d->model->removeColorLabel(row); updateRemoveButtonStatus(); } } void SettingsColorLabelWidget::updateRemoveButtonStatus() { /// Enable remove button iff tree view's selection is not empty d->buttonRemove->setEnabled(!d->view->selectionModel()->selectedIndexes().isEmpty()); } class ColorLabelContextMenu::Private { private: ColorLabelContextMenu *p; public: /// Tree view to show this context menu in FileView *fileView; /// Actual menu to show KActionMenu *menu; Private(FileView *fv, ColorLabelContextMenu *parent) : p(parent), fileView(fv) { menu = new KActionMenu(QIcon::fromTheme(QStringLiteral("preferences-desktop-color")), i18n("Color"), fileView); /// Let menu be a sub menu to the tree view's context menu fileView->addAction(menu); } void rebuildMenu() { menu->menu()->clear(); /// Add color-label pairs to menu as stored /// in the user's configuration file for (QVector>::ConstIterator it = Preferences::instance().colorCodes().constBegin(); it != Preferences::instance().colorCodes().constEnd(); ++it) { QAction *action = new QAction(QIcon(ColorLabelWidget::createSolidIcon(it->first)), it->second, menu); menu->addAction(action); const QString colorCode = it->first.name(); connect(action, &QAction::triggered, p, [this, colorCode]() { colorActivated(colorCode); }); } QAction *action = new QAction(menu); action->setSeparator(true); menu->addAction(action); /// Special action that removes any color /// from a BibTeX entry by setting the color to black action = new QAction(i18n("No color"), menu); menu->addAction(action); connect(action, &QAction::triggered, p, [this]() { colorActivated(QStringLiteral("#000000")); }); } void colorActivated(const QString &colorString) { /// User activated some color from the menu, so apply this color /// code to the currently selected item in the tree view SortFilterFileModel *sfbfm = qobject_cast(fileView->model()); if (sfbfm == nullptr) { /// Something went horribly wrong return; } FileModel *model = sfbfm->fileSourceModel(); if (model == nullptr) { /// Something went horribly wrong return; } /// Apply color change to all selected rows const QModelIndexList list = fileView->selectionModel()->selectedIndexes(); for (const QModelIndex &index : list) { const QModelIndex mappedIndex = sfbfm->mapToSource(index); /// Selection may span over multiple columns; /// to avoid duplicate assignments, consider only column 1 if (mappedIndex.column() == 1) { const int row = mappedIndex.row(); QSharedPointer entry = model->element(row).dynamicCast(); if (!entry.isNull()) { /// Clear old color entry bool modifying = entry->remove(Entry::ftColor) > 0; if (colorString != QStringLiteral("#000000")) { ///< black is a special color that means "no color" /// Only if valid color was selected, set this color Value v; v.append(QSharedPointer(new VerbatimText(colorString))); entry->insert(Entry::ftColor, v); modifying = true; } if (modifying) model->elementChanged(row); } } } } }; ColorLabelContextMenu::ColorLabelContextMenu(FileView *widget) : QObject(widget), d(new Private(widget, this)) { /// Listen to changes in the configuration files NotificationHub::registerNotificationListener(this, NotificationHub::EventConfigurationChanged); d->rebuildMenu(); } ColorLabelContextMenu::~ColorLabelContextMenu() { delete d; } KActionMenu *ColorLabelContextMenu::menuAction() { return d->menu; } void ColorLabelContextMenu::setEnabled(bool enabled) { d->menu->setEnabled(enabled); } void ColorLabelContextMenu::notificationEvent(int eventId) { if (eventId == NotificationHub::EventConfigurationChanged) d->rebuildMenu(); } #include "settingscolorlabelwidget.moc" diff --git a/src/gui/preferences/settingscolorlabelwidget.h b/src/gui/preferences/settingscolorlabelwidget.h index 7ed07d9d..c2949cb3 100644 --- a/src/gui/preferences/settingscolorlabelwidget.h +++ b/src/gui/preferences/settingscolorlabelwidget.h @@ -1,80 +1,80 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSCOLORLABELWIDGET_H #define KBIBTEX_GUI_SETTINGSCOLORLABELWIDGET_H #include #include #include "kbibtexgui_export.h" class KActionMenu; class FileView; /** * @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsColorLabelWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsColorLabelWidget(QWidget *parent); ~SettingsColorLabelWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; private slots: void addColor(); void removeColor(); void updateRemoveButtonStatus(); private: class Private; Private *d; }; /** @author Thomas Fischer */ class KBIBTEXGUI_EXPORT ColorLabelContextMenu : public QObject, private NotificationListener { Q_OBJECT public: explicit ColorLabelContextMenu(FileView *widget); ~ColorLabelContextMenu() override; KActionMenu *menuAction(); void setEnabled(bool); void notificationEvent(int eventId) override; private: class Private; Private *const d; }; #endif // KBIBTEX_GUI_SETTINGSCOLORLABELWIDGET_H diff --git a/src/gui/preferences/settingscolorlabelwidget_p.h b/src/gui/preferences/settingscolorlabelwidget_p.h index d5ec0755..75ac0e64 100644 --- a/src/gui/preferences/settingscolorlabelwidget_p.h +++ b/src/gui/preferences/settingscolorlabelwidget_p.h @@ -1,58 +1,58 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSCOLORLABELWIDGET_P_H #define KBIBTEX_GUI_SETTINGSCOLORLABELWIDGET_P_H #include #include /** * This model maintains a list of label-color pairs. * @author Thomas Fischer */ class ColorLabelSettingsModel : public QAbstractItemModel { Q_OBJECT public: explicit ColorLabelSettingsModel(QObject *parent); int rowCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override; QModelIndex index(int row, int column, const QModelIndex &parent) const override; QModelIndex parent(const QModelIndex &) const override; QVariant data(const QModelIndex &index, int role) const override; bool setData(const QModelIndex &index, const QVariant &value, int role) override; Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; void loadState(); - void saveState(); + bool saveState(); void resetToDefaults(); void addColorLabel(const QColor &color, const QString &label); void removeColorLabel(int row); signals: void modified(); private: QVector> colorLabelPairs; }; #endif // KBIBTEX_GUI_SETTINGSCOLORLABELWIDGET_P_H diff --git a/src/gui/preferences/settingsfileexporterpdfpswidget.cpp b/src/gui/preferences/settingsfileexporterpdfpswidget.cpp index 0b8e73b7..6c9b74c5 100644 --- a/src/gui/preferences/settingsfileexporterpdfpswidget.cpp +++ b/src/gui/preferences/settingsfileexporterpdfpswidget.cpp @@ -1,142 +1,143 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsfileexporterpdfpswidget.h" #include #include #include #include #include #include #include #include "guihelper.h" class SettingsFileExporterPDFPSWidget::SettingsFileExporterPDFPSWidgetPrivate { private: SettingsFileExporterPDFPSWidget *p; QComboBox *comboBoxPaperSize; QComboBox *comboBoxBabelLanguage; QComboBox *comboBoxBibliographyStyle; public: SettingsFileExporterPDFPSWidgetPrivate(SettingsFileExporterPDFPSWidget *parent) : p(parent) { setupGUI(); } void loadState() { int row = qMax(0, GUIHelper::selectValue(comboBoxPaperSize->model(), static_cast(Preferences::instance().pageSize()), Qt::UserRole)); comboBoxPaperSize->setCurrentIndex(row); const QString babelLanguage = Preferences::instance().laTeXBabelLanguage(); row = qMax(0, GUIHelper::selectValue(comboBoxBabelLanguage->model(), babelLanguage)); comboBoxBabelLanguage->setCurrentIndex(row); const QString bibliographyStyle = Preferences::instance().bibTeXBibliographyStyle(); row = qMax(0, GUIHelper::selectValue(comboBoxBibliographyStyle->model(), bibliographyStyle)); comboBoxBibliographyStyle->setCurrentIndex(row); } - void saveState() { - Preferences::instance().setPageSize(static_cast(comboBoxPaperSize->currentData().toInt())); - - Preferences::instance().setLaTeXBabelLanguage(comboBoxBabelLanguage->lineEdit()->text()); - Preferences::instance().setBibTeXBibliographyStyle(comboBoxBibliographyStyle->lineEdit()->text()); + bool saveState() { + bool settingsGotChanged = false; + settingsGotChanged |= Preferences::instance().setPageSize(static_cast(comboBoxPaperSize->currentData().toInt())); + settingsGotChanged |= Preferences::instance().setLaTeXBabelLanguage(comboBoxBabelLanguage->lineEdit()->text()); + settingsGotChanged |= Preferences::instance().setBibTeXBibliographyStyle(comboBoxBibliographyStyle->lineEdit()->text()); + return settingsGotChanged; } void resetToDefaults() { int row = qMax(0, GUIHelper::selectValue(comboBoxPaperSize->model(), static_cast(Preferences::defaultPageSize), Qt::UserRole)); comboBoxPaperSize->setCurrentIndex(row); row = qMax(0, GUIHelper::selectValue(comboBoxBabelLanguage->model(), Preferences::defaultLaTeXBabelLanguage)); comboBoxBabelLanguage->setCurrentIndex(row); row = qMax(0, GUIHelper::selectValue(comboBoxBibliographyStyle->model(), Preferences::defaultBibTeXBibliographyStyle)); comboBoxBibliographyStyle->setCurrentIndex(row); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); comboBoxPaperSize = new QComboBox(p); comboBoxPaperSize->setObjectName(QStringLiteral("comboBoxPaperSize")); layout->addRow(i18n("Paper Size:"), comboBoxPaperSize); for (const auto &dbItem : Preferences::availablePageSizes) comboBoxPaperSize->addItem(QPageSize::name(dbItem.first), dbItem.second); connect(comboBoxPaperSize, static_cast(&QComboBox::currentIndexChanged), p, &SettingsAbstractWidget::changed); comboBoxBabelLanguage = new QComboBox(p); comboBoxBabelLanguage->setObjectName(QStringLiteral("comboBoxBabelLanguage")); comboBoxBabelLanguage->setEditable(true); layout->addRow(i18n("Language for 'babel':"), comboBoxBabelLanguage); comboBoxBabelLanguage->addItem(QStringLiteral("english")); comboBoxBabelLanguage->addItem(QStringLiteral("ngerman")); comboBoxBabelLanguage->addItem(QStringLiteral("swedish")); connect(comboBoxBabelLanguage->lineEdit(), &QLineEdit::textChanged, p, &SettingsFileExporterPDFPSWidget::changed); comboBoxBibliographyStyle = new QComboBox(p); comboBoxBibliographyStyle->setObjectName(QStringLiteral("comboBoxBibliographyStyle")); comboBoxBibliographyStyle->setEditable(true); layout->addRow(i18n("Bibliography style:"), comboBoxBibliographyStyle); static const QStringList styles {QString(QStringLiteral("abbrv")), QString(QStringLiteral("alpha")), QString(QStringLiteral("plain")), QString(QStringLiteral("agsm")), QString(QStringLiteral("dcu")), QString(QStringLiteral("jmr")), QString(QStringLiteral("jphysicsB")), QString(QStringLiteral("kluwer")), QString(QStringLiteral("nederlands"))}; for (const QString &style : styles) { comboBoxBibliographyStyle->addItem(style); } connect(comboBoxBibliographyStyle->lineEdit(), &QLineEdit::textChanged, p, &SettingsFileExporterPDFPSWidget::changed); } }; SettingsFileExporterPDFPSWidget::SettingsFileExporterPDFPSWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsFileExporterPDFPSWidgetPrivate(this)) { d->loadState(); } SettingsFileExporterPDFPSWidget::~SettingsFileExporterPDFPSWidget() { delete d; } QString SettingsFileExporterPDFPSWidget::label() const { return i18n("PDF & Postscript"); } QIcon SettingsFileExporterPDFPSWidget::icon() const { return QIcon::fromTheme(QStringLiteral("application-pdf")); } void SettingsFileExporterPDFPSWidget::loadState() { d->loadState(); } -void SettingsFileExporterPDFPSWidget::saveState() +bool SettingsFileExporterPDFPSWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsFileExporterPDFPSWidget::resetToDefaults() { d->resetToDefaults(); } diff --git a/src/gui/preferences/settingsfileexporterpdfpswidget.h b/src/gui/preferences/settingsfileexporterpdfpswidget.h index 3b95bfea..6c181d78 100644 --- a/src/gui/preferences/settingsfileexporterpdfpswidget.h +++ b/src/gui/preferences/settingsfileexporterpdfpswidget.h @@ -1,49 +1,49 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSFILEEXPORTERPDFPSWIDGET_H #define KBIBTEX_GUI_SETTINGSFILEEXPORTERPDFPSWIDGET_H #include #include "kbibtexgui_export.h" /** * @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsFileExporterPDFPSWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsFileExporterPDFPSWidget(QWidget *parent); ~SettingsFileExporterPDFPSWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; private: class SettingsFileExporterPDFPSWidgetPrivate; SettingsFileExporterPDFPSWidgetPrivate *d; }; #endif // KBIBTEX_GUI_SETTINGSFILEEXPORTERPDFPSWIDGET_H diff --git a/src/gui/preferences/settingsfileexporterwidget.cpp b/src/gui/preferences/settingsfileexporterwidget.cpp index d264a0a7..8c28570c 100644 --- a/src/gui/preferences/settingsfileexporterwidget.cpp +++ b/src/gui/preferences/settingsfileexporterwidget.cpp @@ -1,212 +1,215 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsfileexporterwidget.h" #include #include #include #include #include #include #include #include #include #include /// required as KUrlRequester returns it #include #include #include #include "guihelper.h" #include "italictextitemmodel.h" #include "file/clipboard.h" class SettingsFileExporterWidget::SettingsFileExporterWidgetPrivate { private: SettingsFileExporterWidget *p; QComboBox *comboBoxCopyReferenceCmd; static const QString citeCmdToLabel; public: #ifdef QT_LSTAT QCheckBox *checkboxUseAutomaticLyXPipeDetection; #endif // QT_LSTAT QComboBox *comboBoxBackupScope; QSpinBox *spinboxNumberOfBackups; KUrlRequester *lineeditLyXPipePath; #ifdef QT_LSTAT QString lastUserInputLyXPipePath; #endif // QT_LSTAT SettingsFileExporterWidgetPrivate(SettingsFileExporterWidget *parent) : p(parent) { setupGUI(); } void loadState() { int row = GUIHelper::selectValue(comboBoxCopyReferenceCmd->model(), Preferences::instance().copyReferenceCommand(), ItalicTextItemModel::IdentifierRole); comboBoxCopyReferenceCmd->setCurrentIndex(row); const int index = qMax(0, comboBoxBackupScope->findData(static_cast(Preferences::instance().backupScope()))); comboBoxBackupScope->setCurrentIndex(index); spinboxNumberOfBackups->setValue(qMax(0, qMin(spinboxNumberOfBackups->maximum(), Preferences::instance().numberOfBackups()))); #ifndef QT_LSTAT lineeditLyXPipePath->setText(Preferences::instance().lyXPipePath()); #else // QT_LSTAT checkboxUseAutomaticLyXPipeDetection->setChecked(Preferences::instance().lyXUseAutomaticPipeDetection()); lastUserInputLyXPipePath = Preferences::instance().lyXPipePath(); p->automaticLyXDetectionToggled(checkboxUseAutomaticLyXPipeDetection->isChecked()); #endif // QT_LSTAT } - void saveState() { - Preferences::instance().setCopyReferenceCommand(comboBoxCopyReferenceCmd->itemData(comboBoxCopyReferenceCmd->currentIndex(), ItalicTextItemModel::IdentifierRole).toString()); - Preferences::instance().setBackupScope(static_cast(comboBoxBackupScope->itemData(comboBoxBackupScope->currentIndex()).toInt())); - Preferences::instance().setNumberOfBackups(spinboxNumberOfBackups->value()); + bool saveState() { + bool settingsGotChanged = false; + settingsGotChanged |= Preferences::instance().setCopyReferenceCommand(comboBoxCopyReferenceCmd->itemData(comboBoxCopyReferenceCmd->currentIndex(), ItalicTextItemModel::IdentifierRole).toString()); + settingsGotChanged |= Preferences::instance().setBackupScope(static_cast(comboBoxBackupScope->itemData(comboBoxBackupScope->currentIndex()).toInt())); + settingsGotChanged |= Preferences::instance().setNumberOfBackups(spinboxNumberOfBackups->value()); #ifndef QT_LSTAT - Preferences::instance().setLyXPipePath(lineeditLyXPipePath->text()); + settingsGotChanged |= Preferences::instance().setLyXPipePath(lineeditLyXPipePath->text()); #else // QT_LSTAT - Preferences::instance().setLyXUseAutomaticPipeDetection(checkboxUseAutomaticLyXPipeDetection->isChecked()); - Preferences::instance().setLyXPipePath(checkboxUseAutomaticLyXPipeDetection->isChecked() ? lastUserInputLyXPipePath : lineeditLyXPipePath->text()); + settingsGotChanged |= Preferences::instance().setLyXUseAutomaticPipeDetection(checkboxUseAutomaticLyXPipeDetection->isChecked()); + settingsGotChanged |= Preferences::instance().setLyXPipePath(checkboxUseAutomaticLyXPipeDetection->isChecked() ? lastUserInputLyXPipePath : lineeditLyXPipePath->text()); #endif // QT_LSTAT + + return settingsGotChanged; } void resetToDefaults() { int row = GUIHelper::selectValue(comboBoxCopyReferenceCmd->model(), QString(), Qt::UserRole); comboBoxCopyReferenceCmd->setCurrentIndex(row); const int index = qMax(0, comboBoxBackupScope->findData(Preferences::defaultBackupScope)); comboBoxBackupScope->setCurrentIndex(index); spinboxNumberOfBackups->setValue(qMax(0, qMin(spinboxNumberOfBackups->maximum(), Preferences::defaultNumberOfBackups))); #ifndef QT_LSTAT const QString pipe = Preferences::defaultLyXPipePath; #else // QT_LSTAT checkboxUseAutomaticLyXPipeDetection->setChecked(Preferences::defaultLyXUseAutomaticPipeDetection); QString pipe = LyX::guessLyXPipeLocation(); if (pipe.isEmpty()) pipe = Preferences::defaultLyXPipePath; #endif // QT_LSTAT lineeditLyXPipePath->setText(pipe); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); comboBoxCopyReferenceCmd = new QComboBox(p); comboBoxCopyReferenceCmd->setObjectName(QStringLiteral("comboBoxCopyReferenceCmd")); layout->addRow(i18n("Command for 'Copy Reference':"), comboBoxCopyReferenceCmd); ItalicTextItemModel *itim = new ItalicTextItemModel(); itim->addItem(i18n("No command"), QString()); for (const QString &citeCommand : Preferences::availableCopyReferenceCommands) itim->addItem(citeCmdToLabel.arg(citeCommand), citeCommand); comboBoxCopyReferenceCmd->setModel(itim); connect(comboBoxCopyReferenceCmd, static_cast(&QComboBox::currentIndexChanged), p, &SettingsFileExporterWidget::changed); #ifdef QT_LSTAT checkboxUseAutomaticLyXPipeDetection = new QCheckBox(QString(), p); layout->addRow(i18n("Detect LyX pipe automatically:"), checkboxUseAutomaticLyXPipeDetection); connect(checkboxUseAutomaticLyXPipeDetection, &QCheckBox::toggled, p, &SettingsFileExporterWidget::changed); connect(checkboxUseAutomaticLyXPipeDetection, &QCheckBox::toggled, p, &SettingsFileExporterWidget::automaticLyXDetectionToggled); #endif // QT_LSTAT lineeditLyXPipePath = new KUrlRequester(p); layout->addRow(i18n("Manually specified LyX pipe:"), lineeditLyXPipePath); connect(qobject_cast(lineeditLyXPipePath->lineEdit()), &QLineEdit::textEdited, p, &SettingsFileExporterWidget::changed); #if QT_VERSION >= 0x050b00 lineeditLyXPipePath->setMinimumWidth(lineeditLyXPipePath->fontMetrics().horizontalAdvance(QChar('W')) * 20); #else // QT_VERSION >= 0x050b00 lineeditLyXPipePath->setMinimumWidth(lineeditLyXPipePath->fontMetrics().width(QChar('W')) * 20); #endif // QT_VERSION >= 0x050b00 lineeditLyXPipePath->setFilter(QStringLiteral("inode/fifo")); lineeditLyXPipePath->setMode(KFile::ExistingOnly | KFile::LocalOnly); comboBoxBackupScope = new QComboBox(p); for (const auto &pair : Preferences::availableBackupScopes) comboBoxBackupScope->addItem(pair.second, static_cast(pair.first)); layout->addRow(i18n("Backups when saving:"), comboBoxBackupScope); connect(comboBoxBackupScope, static_cast(&QComboBox::currentIndexChanged), p, &SettingsFileExporterWidget::changed); spinboxNumberOfBackups = new QSpinBox(p); spinboxNumberOfBackups->setMinimum(1); spinboxNumberOfBackups->setMaximum(16); layout->addRow(i18n("Number of Backups:"), spinboxNumberOfBackups); connect(spinboxNumberOfBackups, static_cast(&QSpinBox::valueChanged), p, &SettingsFileExporterWidget::changed); connect(comboBoxBackupScope, static_cast(&QComboBox::currentIndexChanged), p, &SettingsFileExporterWidget::updateGUI); } }; const QString SettingsFileExporterWidget::SettingsFileExporterWidgetPrivate::citeCmdToLabel = QStringLiteral("\\%1{") + QChar(0x2026) + QChar('}'); SettingsFileExporterWidget::SettingsFileExporterWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsFileExporterWidgetPrivate(this)) { d->loadState(); } SettingsFileExporterWidget::~SettingsFileExporterWidget() { delete d; } QString SettingsFileExporterWidget::label() const { return i18n("Saving and Exporting"); } QIcon SettingsFileExporterWidget::icon() const { return QIcon::fromTheme(QStringLiteral("document-save")); } void SettingsFileExporterWidget::loadState() { d->loadState(); } -void SettingsFileExporterWidget::saveState() +bool SettingsFileExporterWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsFileExporterWidget::resetToDefaults() { d->resetToDefaults(); } #ifdef QT_LSTAT void SettingsFileExporterWidget::automaticLyXDetectionToggled(bool isChecked) { d->lineeditLyXPipePath->setEnabled(!isChecked); if (isChecked) { d->lastUserInputLyXPipePath = d->lineeditLyXPipePath->text(); d->lineeditLyXPipePath->setText(LyX::guessLyXPipeLocation()); } else d->lineeditLyXPipePath->setText(d->lastUserInputLyXPipePath); } #endif // QT_LSTAT void SettingsFileExporterWidget::updateGUI() { d->spinboxNumberOfBackups->setEnabled(d->comboBoxBackupScope->itemData(d->comboBoxBackupScope->currentIndex()).toInt() != static_cast(Preferences::NoBackup)); } diff --git a/src/gui/preferences/settingsfileexporterwidget.h b/src/gui/preferences/settingsfileexporterwidget.h index 34db7557..9b20507b 100644 --- a/src/gui/preferences/settingsfileexporterwidget.h +++ b/src/gui/preferences/settingsfileexporterwidget.h @@ -1,58 +1,58 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSFILEEXPORTERWIDGET_H #define KBIBTEX_GUI_SETTINGSFILEEXPORTERWIDGET_H #include #include #include "kbibtexgui_export.h" /** * @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsFileExporterWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsFileExporterWidget(QWidget *parent); ~SettingsFileExporterWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; #ifdef QT_LSTAT void automaticLyXDetectionToggled(bool); #endif // QT_LSTAT private slots: void updateGUI(); private: class SettingsFileExporterWidgetPrivate; SettingsFileExporterWidgetPrivate *d; }; #endif // KBIBTEX_GUI_SETTINGSFILEEXPORTERWIDGET_H diff --git a/src/gui/preferences/settingsgeneralwidget.cpp b/src/gui/preferences/settingsgeneralwidget.cpp index 2156e10b..25d5cffb 100644 --- a/src/gui/preferences/settingsgeneralwidget.cpp +++ b/src/gui/preferences/settingsgeneralwidget.cpp @@ -1,119 +1,121 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsgeneralwidget.h" #include #include #include #include "preferences.h" #include "value.h" #include "guihelper.h" class SettingsGeneralWidget::SettingsGeneralWidgetPrivate { private: SettingsGeneralWidget *p; QComboBox *comboBoxBibliographySystem; QComboBox *comboBoxPersonNameFormatting; const Person dummyPerson; public: SettingsGeneralWidgetPrivate(SettingsGeneralWidget *parent) : p(parent), dummyPerson(Person(i18n("John"), i18n("Doe"), i18n("Jr."))) { setupGUI(); } void loadState() { comboBoxBibliographySystem->setCurrentIndex(comboBoxBibliographySystem->findData(QVariant::fromValue(static_cast(Preferences::instance().bibliographySystem())))); int row = GUIHelper::selectValue(comboBoxPersonNameFormatting->model(), Person::transcribePersonName(&dummyPerson, Preferences::instance().personNameFormat())); comboBoxPersonNameFormatting->setCurrentIndex(row); } - void saveState() { - Preferences::instance().setBibliographySystem(static_cast(comboBoxBibliographySystem->currentData().toInt())); - Preferences::instance().setPersonNameFormat(comboBoxPersonNameFormatting->itemData(comboBoxPersonNameFormatting->currentIndex()).toString()); + bool saveState() { + bool settingsGotChanged = false; + settingsGotChanged |= Preferences::instance().setBibliographySystem(static_cast(comboBoxBibliographySystem->currentData().toInt())); + settingsGotChanged |= Preferences::instance().setPersonNameFormat(comboBoxPersonNameFormatting->itemData(comboBoxPersonNameFormatting->currentIndex()).toString()); + return settingsGotChanged; } void resetToDefaults() { comboBoxBibliographySystem->setCurrentIndex(static_cast(Preferences::defaultBibliographySystem)); int row = GUIHelper::selectValue(comboBoxPersonNameFormatting->model(), Person::transcribePersonName(&dummyPerson, Preferences::defaultPersonNameFormat)); comboBoxPersonNameFormatting->setCurrentIndex(row); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); comboBoxBibliographySystem = new QComboBox(p); comboBoxBibliographySystem->setObjectName(QStringLiteral("comboBoxBibliographySystem")); for (QVector>::ConstIterator it = Preferences::availableBibliographySystems.constBegin(); it != Preferences::availableBibliographySystems.constEnd(); ++it) comboBoxBibliographySystem->addItem(it->second, QVariant::fromValue(static_cast(it->first))); layout->addRow(i18n("Bibliography System:"), comboBoxBibliographySystem); connect(comboBoxBibliographySystem, static_cast(&QComboBox::currentIndexChanged), p, &SettingsGeneralWidget::changed); comboBoxPersonNameFormatting = new QComboBox(p); layout->addRow(i18n("Person Names Formatting:"), comboBoxPersonNameFormatting); static const QStringList formattingOptions {Preferences::personNameFormatFirstLast, Preferences::personNameFormatLastFirst}; for (const QString &formattingOption : formattingOptions) comboBoxPersonNameFormatting->addItem(Person::transcribePersonName(&dummyPerson, formattingOption), formattingOption); connect(comboBoxPersonNameFormatting, static_cast(&QComboBox::currentIndexChanged), p, &SettingsGeneralWidget::changed); } }; SettingsGeneralWidget::SettingsGeneralWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsGeneralWidgetPrivate(this)) { d->loadState(); } SettingsGeneralWidget::~SettingsGeneralWidget() { delete d; } QString SettingsGeneralWidget::label() const { return i18n("General"); } QIcon SettingsGeneralWidget::icon() const { return QIcon::fromTheme(QStringLiteral("kbibtex")); } void SettingsGeneralWidget::loadState() { d->loadState(); } -void SettingsGeneralWidget::saveState() +bool SettingsGeneralWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsGeneralWidget::resetToDefaults() { d->resetToDefaults(); } diff --git a/src/gui/preferences/settingsgeneralwidget.h b/src/gui/preferences/settingsgeneralwidget.h index 55d35e0a..b9907467 100644 --- a/src/gui/preferences/settingsgeneralwidget.h +++ b/src/gui/preferences/settingsgeneralwidget.h @@ -1,50 +1,50 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSGENERALWIDGET_H #define KBIBTEX_GUI_SETTINGSGENERALWIDGET_H #include #include "kbibtexgui_export.h" /** * @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsGeneralWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsGeneralWidget(QWidget *parent); ~SettingsGeneralWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; private: class SettingsGeneralWidgetPrivate; SettingsGeneralWidgetPrivate *d; }; #endif // KBIBTEX_GUI_SETTINGSGENERALWIDGET_H diff --git a/src/gui/preferences/settingsglobalkeywordswidget.cpp b/src/gui/preferences/settingsglobalkeywordswidget.cpp index 41cd9005..c076eb94 100644 --- a/src/gui/preferences/settingsglobalkeywordswidget.cpp +++ b/src/gui/preferences/settingsglobalkeywordswidget.cpp @@ -1,169 +1,171 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsglobalkeywordswidget.h" #include #include #include #include #include #include #include #include "field/fieldlistedit.h" class DisallowEmptyStringListModel : public QStringListModel { Q_OBJECT public: explicit DisallowEmptyStringListModel(QObject *parent) : QStringListModel(parent) { /// nothing } bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override { if (role == Qt::EditRole && value.canConvert() && value.toString().isEmpty()) return false; /// do not accept values that are empty else return QStringListModel::setData(index, value, role); } }; class SettingsGlobalKeywordsWidget::SettingsGlobalKeywordsWidgetPrivate { private: SettingsGlobalKeywordsWidget *p; KSharedConfigPtr config; const QString configGroupName; public: QListView *listViewKeywords; DisallowEmptyStringListModel stringListModel; QPushButton *buttonRemove; static int keywordCounter; SettingsGlobalKeywordsWidgetPrivate(SettingsGlobalKeywordsWidget *parent) : p(parent), config(KSharedConfig::openConfig(QStringLiteral("kbibtexrc"))), configGroupName(QStringLiteral("Global Keywords")), stringListModel(parent) { setupGUI(); } void loadState() { KConfigGroup configGroup(config, configGroupName); QStringList keywordList = configGroup.readEntry(KeywordListEdit::keyGlobalKeywordList, QStringList()); stringListModel.setStringList(keywordList); } - void saveState() { + bool saveState() { KConfigGroup configGroup(config, configGroupName); + const QStringList oldGlobalKeywordList = configGroup.readEntry(KeywordListEdit::keyGlobalKeywordList, QStringList()); configGroup.writeEntry(KeywordListEdit::keyGlobalKeywordList, stringListModel.stringList()); config->sync(); + return oldGlobalKeywordList != stringListModel.stringList(); } void resetToDefaults() { /// ignored, you don't want to delete all your keywords ... } void setupGUI() { QGridLayout *layout = new QGridLayout(p); layout->setMargin(0); listViewKeywords = new QListView(p); layout->addWidget(listViewKeywords, 0, 0, 3, 1); listViewKeywords->setModel(&stringListModel); connect(listViewKeywords, &QListView::pressed, p, &SettingsGlobalKeywordsWidget::enableRemoveButton); QPushButton *buttonAdd = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add"), p); layout->addWidget(buttonAdd, 0, 1, 1, 1); connect(buttonAdd, &QPushButton::clicked, p, &SettingsGlobalKeywordsWidget::addKeyword); buttonRemove = new QPushButton(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("Remove"), p); layout->addWidget(buttonRemove, 1, 1, 1, 1); buttonRemove->setEnabled(false); connect(buttonRemove, &QPushButton::clicked, p, &SettingsGlobalKeywordsWidget::removeKeyword); } }; int SettingsGlobalKeywordsWidget::SettingsGlobalKeywordsWidgetPrivate::keywordCounter = 0; SettingsGlobalKeywordsWidget::SettingsGlobalKeywordsWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsGlobalKeywordsWidgetPrivate(this)) { d->loadState(); } SettingsGlobalKeywordsWidget::~SettingsGlobalKeywordsWidget() { delete d; } QString SettingsGlobalKeywordsWidget::label() const { return i18n("Keywords"); } QIcon SettingsGlobalKeywordsWidget::icon() const { return QIcon::fromTheme(QStringLiteral("checkbox")); // TODO find better icon } void SettingsGlobalKeywordsWidget::loadState() { d->loadState(); } -void SettingsGlobalKeywordsWidget::saveState() +bool SettingsGlobalKeywordsWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsGlobalKeywordsWidget::resetToDefaults() { d->resetToDefaults(); } void SettingsGlobalKeywordsWidget::addKeyword() { if (d->stringListModel.insertRow(d->stringListModel.rowCount(), QModelIndex())) { QModelIndex index = d->stringListModel.index(d->stringListModel.rowCount() - 1, 0); d->stringListModel.setData(index, i18n("NewKeyword%1", d->keywordCounter++)); d->listViewKeywords->setCurrentIndex(index); d->listViewKeywords->edit(index); d->buttonRemove->setEnabled(true); } } void SettingsGlobalKeywordsWidget::removeKeyword() { QModelIndex currIndex = d->listViewKeywords->currentIndex(); if (currIndex == QModelIndex()) currIndex = d->listViewKeywords->selectionModel()->selectedIndexes().first(); d->stringListModel.removeRow(currIndex.row()); d->buttonRemove->setEnabled(d->listViewKeywords->currentIndex() != QModelIndex()); } void SettingsGlobalKeywordsWidget::enableRemoveButton() { d->buttonRemove->setEnabled(d->listViewKeywords->currentIndex() != QModelIndex()); } #include "settingsglobalkeywordswidget.moc" diff --git a/src/gui/preferences/settingsglobalkeywordswidget.h b/src/gui/preferences/settingsglobalkeywordswidget.h index e7eff92b..68f7ae6d 100644 --- a/src/gui/preferences/settingsglobalkeywordswidget.h +++ b/src/gui/preferences/settingsglobalkeywordswidget.h @@ -1,56 +1,56 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSGLOBALKEYWORDSWIDGET_H #define KBIBTEX_GUI_SETTINGSGLOBALKEYWORDSWIDGET_H #include "settingsabstractwidget.h" #include "kbibtexgui_export.h" class File; /** * @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsGlobalKeywordsWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsGlobalKeywordsWidget(QWidget *parent); ~SettingsGlobalKeywordsWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; private slots: void addKeyword(); void removeKeyword(); void enableRemoveButton(); private: class SettingsGlobalKeywordsWidgetPrivate; SettingsGlobalKeywordsWidgetPrivate *d; }; #endif // KBIBTEX_GUI_SETTINGSGLOBALKEYWORDSWIDGET_H diff --git a/src/gui/preferences/settingsidsuggestionswidget.cpp b/src/gui/preferences/settingsidsuggestionswidget.cpp index 7a200729..10f38bbb 100644 --- a/src/gui/preferences/settingsidsuggestionswidget.cpp +++ b/src/gui/preferences/settingsidsuggestionswidget.cpp @@ -1,400 +1,402 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsidsuggestionswidget.h" #include #include #include #include #include #include #include #include #include #include "settingsidsuggestionseditor.h" class IdSuggestionsModel : public QAbstractListModel { Q_OBJECT private: QStringList m_formatStringList; int m_defaultFormatStringRow; IdSuggestions *m_idSuggestions; static const QString exampleBibTeXEntryString; static QSharedPointer exampleBibTeXEntry; public: IdSuggestionsModel(QObject *parent = nullptr) : QAbstractListModel(parent) { m_idSuggestions = new IdSuggestions(); m_defaultFormatStringRow = -1; if (exampleBibTeXEntry.isNull()) { FileImporterBibTeX fileImporterBibTeX(this); File *file = fileImporterBibTeX.fromString(exampleBibTeXEntryString); if (file != nullptr) { if (!file->isEmpty()) exampleBibTeXEntry = file->first().dynamicCast(); delete file; } } } ~IdSuggestionsModel() override { delete m_idSuggestions; } enum IdSuggestionsModelRole { /// Raw format string as QString FormatStringRole = Qt::UserRole + 7811, /// Flag whether current index is the default one; boolean value IsDefaultFormatStringRole = Qt::UserRole + 7812 }; QSharedPointer previewEntry() { return exampleBibTeXEntry; } void setFormatStringList(const QStringList &formatStringList, const QString &defaultString = QString()) { beginResetModel(); m_formatStringList = formatStringList; m_defaultFormatStringRow = m_formatStringList.indexOf(defaultString); endResetModel(); } QStringList formatStringList() const { return this->m_formatStringList; } QString defaultFormatString() const { if (m_defaultFormatStringRow >= 0 && m_defaultFormatStringRow < m_formatStringList.length()) return m_formatStringList[m_defaultFormatStringRow]; else return QString(); } int rowCount(const QModelIndex &parent = QModelIndex()) const override { if (parent == QModelIndex()) return m_formatStringList.count(); else return 0; } QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override { if (index.row() < 0 || index.row() >= m_formatStringList.count()) return QVariant(); switch (role) { case Qt::FontRole: { QFont defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont); if (index.row() == m_defaultFormatStringRow) defaultFont.setBold(true); return defaultFont; } case Qt::DecorationRole: if (index.row() == m_defaultFormatStringRow) return QIcon::fromTheme(QStringLiteral("favorites")); else return QIcon::fromTheme(QStringLiteral("view-filter")); case Qt::ToolTipRole: return i18n("Structure:
  • %1
Example: %2
", m_idSuggestions->formatStrToHuman(m_formatStringList[index.row()]).join(QStringLiteral("
  • ")), m_idSuggestions->formatId(*exampleBibTeXEntry, m_formatStringList[index.row()])); case Qt::DisplayRole: return m_idSuggestions->formatId(*exampleBibTeXEntry, m_formatStringList[index.row()]); case Qt::UserRole: case FormatStringRole: return m_formatStringList[index.row()]; case IsDefaultFormatStringRole: return index.row() == m_defaultFormatStringRow; default: return QVariant(); } } bool setData(const QModelIndex &idx, const QVariant &value, int role) override { if (idx.row() < 0 || idx.row() >= m_formatStringList.count()) return false; if (role == IsDefaultFormatStringRole && value.canConvert()) { if (value.toBool()) { if (idx.row() != m_defaultFormatStringRow) { QModelIndex oldDefaultIndex = index(m_defaultFormatStringRow, 0); m_defaultFormatStringRow = idx.row(); emit dataChanged(oldDefaultIndex, oldDefaultIndex); emit dataChanged(idx, idx); } } else { m_defaultFormatStringRow = -1; emit dataChanged(idx, idx); } return true; } else if (role == FormatStringRole && value.canConvert()) { m_formatStringList[idx.row()] = value.toString(); emit dataChanged(idx, idx); return true; } return false; } virtual bool insertRow(int row, const QModelIndex &parent = QModelIndex()) { if (parent != QModelIndex()) return false; beginInsertRows(parent, row, row); m_formatStringList.insert(row, QStringLiteral("T")); endInsertRows(); return true; } QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const override { if (role == Qt::DisplayRole && section == 0) return i18n("Id Suggestions"); return QVariant(); } bool moveUp(const QModelIndex &index) { int row = index.row(); if (row < 1 || row >= m_formatStringList.count()) return false; beginMoveColumns(index.parent(), row, row, index.parent(), row - 1); const QString formatString = m_formatStringList[row]; m_formatStringList.removeAt(row); m_formatStringList.insert(row - 1, formatString); if (m_defaultFormatStringRow == row) --m_defaultFormatStringRow; ///< update default id suggestion endMoveRows(); return true; } bool moveDown(const QModelIndex &index) { int row = index.row(); if (row < 0 || row >= m_formatStringList.count() - 1) return false; beginMoveColumns(index.parent(), row + 1, row + 1, index.parent(), row); const QString formatString = m_formatStringList[row]; m_formatStringList.removeAt(row); m_formatStringList.insert(row + 1, formatString); if (m_defaultFormatStringRow == row) ++m_defaultFormatStringRow; ///< update default id suggestion endMoveRows(); return true; } bool remove(const QModelIndex &index) { int row = index.row(); if (row < 0 || row >= m_formatStringList.count()) return false; beginRemoveRows(index.parent(), row, row); m_formatStringList.removeAt(row); if (m_defaultFormatStringRow == row) m_defaultFormatStringRow = -1; ///< update default id suggestion endRemoveRows(); return true; } }; const QString IdSuggestionsModel::exampleBibTeXEntryString = QStringLiteral("@Article{ dijkstra1983terminationdetect,\nauthor = {Edsger W. Dijkstra and W. H. J. Feijen and A. J. M. {van Gasteren}},\ntitle = {{Derivation of a Termination Detection Algorithm for Distributed Computations}},\njournal = {Information Processing Letters},\nvolume = 16,\nnumber = 5,\npages = {217--219},\nmonth = jun,\nyear = 1983\n}"); QSharedPointer IdSuggestionsModel::exampleBibTeXEntry; class SettingsIdSuggestionsWidget::SettingsIdSuggestionsWidgetPrivate { private: SettingsIdSuggestionsWidget *p; public: QTreeView *treeViewSuggestions; IdSuggestionsModel *idSuggestionsModel; QPushButton *buttonNewSuggestion, *buttonEditSuggestion, *buttonDeleteSuggestion, *buttonSuggestionUp, *buttonSuggestionDown, *buttonToggleDefaultString; SettingsIdSuggestionsWidgetPrivate(SettingsIdSuggestionsWidget *parent) : p(parent) { setupGUI(); } void loadState() { idSuggestionsModel->setFormatStringList(Preferences::instance().idSuggestionFormatStrings(), Preferences::instance().activeIdSuggestionFormatString()); } - void saveState() { - Preferences::instance().setIdSuggestionFormatStrings(idSuggestionsModel->formatStringList()); - Preferences::instance().setActiveIdSuggestionFormatString(idSuggestionsModel->defaultFormatString()); + bool saveState() { + bool settingsGotChanged = false; + settingsGotChanged |= Preferences::instance().setIdSuggestionFormatStrings(idSuggestionsModel->formatStringList()); + settingsGotChanged |= Preferences::instance().setActiveIdSuggestionFormatString(idSuggestionsModel->defaultFormatString()); + return settingsGotChanged; } void resetToDefaults() { idSuggestionsModel->setFormatStringList(Preferences::defaultIdSuggestionFormatStrings); } void setupGUI() { QGridLayout *layout = new QGridLayout(p); treeViewSuggestions = new QTreeView(p); layout->addWidget(treeViewSuggestions, 0, 0, 8, 1); idSuggestionsModel = new IdSuggestionsModel(treeViewSuggestions); treeViewSuggestions->setModel(idSuggestionsModel); treeViewSuggestions->setRootIsDecorated(false); connect(treeViewSuggestions->selectionModel(), &QItemSelectionModel::currentChanged, p, &SettingsIdSuggestionsWidget::itemChanged); #if QT_VERSION >= 0x050b00 treeViewSuggestions->setMinimumSize(treeViewSuggestions->fontMetrics().horizontalAdvance(QChar('W')) * 25, treeViewSuggestions->fontMetrics().height() * 15); #else // QT_VERSION >= 0x050b00 treeViewSuggestions->setMinimumSize(treeViewSuggestions->fontMetrics().width(QChar('W')) * 25, treeViewSuggestions->fontMetrics().height() * 15); #endif // QT_VERSION >= 0x050b00 buttonNewSuggestion = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Add..."), p); layout->addWidget(buttonNewSuggestion, 0, 1, 1, 1); buttonEditSuggestion = new QPushButton(QIcon::fromTheme(QStringLiteral("document-edit")), i18n("Edit..."), p); layout->addWidget(buttonEditSuggestion, 1, 1, 1, 1); buttonDeleteSuggestion = new QPushButton(QIcon::fromTheme(QStringLiteral("list-remove")), i18n("Remove"), p); layout->addWidget(buttonDeleteSuggestion, 2, 1, 1, 1); buttonSuggestionUp = new QPushButton(QIcon::fromTheme(QStringLiteral("go-up")), i18n("Up"), p); layout->addWidget(buttonSuggestionUp, 3, 1, 1, 1); buttonSuggestionDown = new QPushButton(QIcon::fromTheme(QStringLiteral("go-down")), i18n("Down"), p); layout->addWidget(buttonSuggestionDown, 4, 1, 1, 1); buttonToggleDefaultString = new QPushButton(QIcon::fromTheme(QStringLiteral("favorites")), i18n("Toggle Default"), p); layout->addWidget(buttonToggleDefaultString, 5, 1, 1, 1); connect(buttonNewSuggestion, &QPushButton::clicked, p, &SettingsIdSuggestionsWidget::buttonClicked); connect(buttonEditSuggestion, &QPushButton::clicked, p, &SettingsIdSuggestionsWidget::buttonClicked); connect(buttonDeleteSuggestion, &QPushButton::clicked, p, &SettingsIdSuggestionsWidget::buttonClicked); connect(buttonSuggestionUp, &QPushButton::clicked, p, &SettingsIdSuggestionsWidget::buttonClicked); connect(buttonSuggestionDown, &QPushButton::clicked, p, &SettingsIdSuggestionsWidget::buttonClicked); connect(buttonToggleDefaultString, &QPushButton::clicked, p, &SettingsIdSuggestionsWidget::toggleDefault); connect(treeViewSuggestions, &QTreeView::doubleClicked, p, &SettingsIdSuggestionsWidget::editItem); } }; SettingsIdSuggestionsWidget::SettingsIdSuggestionsWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsIdSuggestionsWidgetPrivate(this)) { d->loadState(); itemChanged(QModelIndex()); } SettingsIdSuggestionsWidget::~SettingsIdSuggestionsWidget() { delete d; } QString SettingsIdSuggestionsWidget::label() const { return i18n("Id Suggestions"); } QIcon SettingsIdSuggestionsWidget::icon() const { return QIcon::fromTheme(QStringLiteral("view-filter")); } void SettingsIdSuggestionsWidget::loadState() { d->loadState(); } -void SettingsIdSuggestionsWidget::saveState() +bool SettingsIdSuggestionsWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsIdSuggestionsWidget::resetToDefaults() { d->resetToDefaults(); } void SettingsIdSuggestionsWidget::buttonClicked() { QPushButton *button = qobject_cast(sender()); QModelIndex selectedIndex = d->treeViewSuggestions->selectionModel()->currentIndex(); if (button == d->buttonNewSuggestion) { const QString newSuggestion = IdSuggestionsEditDialog::editSuggestion(d->idSuggestionsModel->previewEntry().data(), QString(), this); const int row = d->treeViewSuggestions->model()->rowCount(QModelIndex()); if (!newSuggestion.isEmpty() && d->idSuggestionsModel->insertRow(row)) { QModelIndex index = d->idSuggestionsModel->index(row, 0, QModelIndex()); d->treeViewSuggestions->setCurrentIndex(index); if (d->idSuggestionsModel->setData(index, newSuggestion, IdSuggestionsModel::FormatStringRole)) emit changed(); } } else if (button == d->buttonEditSuggestion) { QModelIndex currIndex = d->treeViewSuggestions->currentIndex(); editItem(currIndex); } else if (button == d->buttonDeleteSuggestion) { if (d->idSuggestionsModel->remove(selectedIndex)) { emit changed(); } } else if (button == d->buttonSuggestionUp) { if (d->idSuggestionsModel->moveUp(selectedIndex)) { d->treeViewSuggestions->selectionModel()->setCurrentIndex(selectedIndex.sibling(selectedIndex.row() - 1, 0), QItemSelectionModel::ClearAndSelect); emit changed(); } } else if (button == d->buttonSuggestionDown) { if (d->idSuggestionsModel->moveDown(selectedIndex)) { d->treeViewSuggestions->selectionModel()->setCurrentIndex(selectedIndex.sibling(selectedIndex.row() + 1, 0), QItemSelectionModel::ClearAndSelect); emit changed(); } } } void SettingsIdSuggestionsWidget::itemChanged(const QModelIndex &index) { bool enableChange = index != QModelIndex(); d->buttonEditSuggestion->setEnabled(enableChange); d->buttonDeleteSuggestion->setEnabled(enableChange); d->buttonSuggestionUp->setEnabled(enableChange && index.row() > 0); d->buttonSuggestionDown->setEnabled(enableChange && index.row() < d->idSuggestionsModel->rowCount() - 1); d->buttonToggleDefaultString->setEnabled(enableChange); } void SettingsIdSuggestionsWidget::editItem(const QModelIndex &index) { QString suggestion; if (index != QModelIndex() && !(suggestion = index.data(IdSuggestionsModel::FormatStringRole).toString()).isEmpty()) { const QString newSuggestion = IdSuggestionsEditDialog::editSuggestion(d->idSuggestionsModel->previewEntry().data(), suggestion, this); if (newSuggestion.isEmpty()) { if (KMessageBox::questionYesNo(this, i18n("All token have been removed from this suggestion. Remove suggestion itself or restore original suggestion?"), i18n("Remove suggestion?"), KGuiItem(i18n("Remove suggestion"), QIcon::fromTheme(QStringLiteral("list-remove"))), KGuiItem(i18n("Revert changes"), QIcon::fromTheme(QStringLiteral("edit-undo")))) == KMessageBox::Yes && d->idSuggestionsModel->remove(index)) { emit changed(); } } else if (newSuggestion != suggestion) { if (d->idSuggestionsModel->setData(index, newSuggestion, IdSuggestionsModel::FormatStringRole)) emit changed(); } } } void SettingsIdSuggestionsWidget::toggleDefault() { QModelIndex curIndex = d->treeViewSuggestions->currentIndex(); bool current = d->idSuggestionsModel->data(curIndex, IdSuggestionsModel::IsDefaultFormatStringRole).toBool(); d->idSuggestionsModel->setData(curIndex, !current, IdSuggestionsModel::IsDefaultFormatStringRole); emit changed(); } #include "settingsidsuggestionswidget.moc" diff --git a/src/gui/preferences/settingsidsuggestionswidget.h b/src/gui/preferences/settingsidsuggestionswidget.h index 53043ef9..df8acf53 100644 --- a/src/gui/preferences/settingsidsuggestionswidget.h +++ b/src/gui/preferences/settingsidsuggestionswidget.h @@ -1,55 +1,55 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSIDSUGGESTIONSWIDGET_H #define KBIBTEX_GUI_SETTINGSIDSUGGESTIONSWIDGET_H #include "settingsabstractwidget.h" #include "kbibtexgui_export.h" /** @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsIdSuggestionsWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsIdSuggestionsWidget(QWidget *parent); ~SettingsIdSuggestionsWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; private slots: void buttonClicked(); void itemChanged(const QModelIndex &index); void editItem(const QModelIndex &index); void toggleDefault(); private: class SettingsIdSuggestionsWidgetPrivate; SettingsIdSuggestionsWidgetPrivate *d; }; #endif // KBIBTEX_GUI_SETTINGSIDSUGGESTIONSWIDGET_H diff --git a/src/gui/preferences/settingsuserinterfacewidget.cpp b/src/gui/preferences/settingsuserinterfacewidget.cpp index 628bd664..132e7342 100644 --- a/src/gui/preferences/settingsuserinterfacewidget.cpp +++ b/src/gui/preferences/settingsuserinterfacewidget.cpp @@ -1,105 +1,107 @@ /*************************************************************************** * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "settingsuserinterfacewidget.h" #include #include #include #include #include #include #include "element/elementwidgets.h" #include "guihelper.h" class SettingsUserInterfaceWidget::SettingsUserInterfaceWidgetPrivate { private: SettingsUserInterfaceWidget *p; QComboBox *comboBoxElementDoubleClickAction; public: SettingsUserInterfaceWidgetPrivate(SettingsUserInterfaceWidget *parent) : p(parent) { setupGUI(); } void loadState() { const int row = qMax(0, GUIHelper::selectValue(comboBoxElementDoubleClickAction->model(), static_cast(Preferences::instance().fileViewDoubleClickAction()), Qt::UserRole)); comboBoxElementDoubleClickAction->setCurrentIndex(row); } - void saveState() { - Preferences::instance().setFileViewDoubleClickAction(static_cast(comboBoxElementDoubleClickAction->currentData().toInt())); + bool saveState() { + bool settingsGotChanged = false; + settingsGotChanged |= Preferences::instance().setFileViewDoubleClickAction(static_cast(comboBoxElementDoubleClickAction->currentData().toInt())); + return settingsGotChanged; } void resetToDefaults() { const int row = qMax(0, GUIHelper::selectValue(comboBoxElementDoubleClickAction->model(), static_cast(Preferences::defaultFileViewDoubleClickAction), Qt::UserRole)); comboBoxElementDoubleClickAction->setCurrentIndex(row); } void setupGUI() { QFormLayout *layout = new QFormLayout(p); comboBoxElementDoubleClickAction = new QComboBox(p); comboBoxElementDoubleClickAction->setObjectName(QStringLiteral("comboBoxElementDoubleClickAction")); for (QVector>::ConstIterator it = Preferences::availableFileViewDoubleClickActions.constBegin(); it != Preferences::availableFileViewDoubleClickActions.constEnd(); ++it) comboBoxElementDoubleClickAction->addItem(it->second, static_cast(it->first)); layout->addRow(i18n("When double-clicking an element:"), comboBoxElementDoubleClickAction); connect(comboBoxElementDoubleClickAction, static_cast(&QComboBox::currentIndexChanged), p, &SettingsUserInterfaceWidget::changed); } }; SettingsUserInterfaceWidget::SettingsUserInterfaceWidget(QWidget *parent) : SettingsAbstractWidget(parent), d(new SettingsUserInterfaceWidgetPrivate(this)) { d->loadState(); } QString SettingsUserInterfaceWidget::label() const { return i18n("User Interface"); } QIcon SettingsUserInterfaceWidget::icon() const { return QIcon::fromTheme(QStringLiteral("user-identity")); } SettingsUserInterfaceWidget::~SettingsUserInterfaceWidget() { delete d; } void SettingsUserInterfaceWidget::loadState() { d->loadState(); } -void SettingsUserInterfaceWidget::saveState() +bool SettingsUserInterfaceWidget::saveState() { - d->saveState(); + return d->saveState(); } void SettingsUserInterfaceWidget::resetToDefaults() { d->resetToDefaults(); } diff --git a/src/gui/preferences/settingsuserinterfacewidget.h b/src/gui/preferences/settingsuserinterfacewidget.h index e129edc9..dbad1cd4 100644 --- a/src/gui/preferences/settingsuserinterfacewidget.h +++ b/src/gui/preferences/settingsuserinterfacewidget.h @@ -1,50 +1,50 @@ /*************************************************************************** - * Copyright (C) 2004-2017 by Thomas Fischer * + * Copyright (C) 2004-2019 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_GUI_SETTINGSUSERINTERFACEWIDGET_H #define KBIBTEX_GUI_SETTINGSUSERINTERFACEWIDGET_H #include "settingsabstractwidget.h" #include "kbibtexgui_export.h" /** @author Thomas Fischer */ class KBIBTEXGUI_EXPORT SettingsUserInterfaceWidget : public SettingsAbstractWidget { Q_OBJECT public: explicit SettingsUserInterfaceWidget(QWidget *parent); ~SettingsUserInterfaceWidget() override; QString label() const override; QIcon icon() const override; public slots: void loadState() override; - void saveState() override; + bool saveState() override; void resetToDefaults() override; private: class SettingsUserInterfaceWidgetPrivate; SettingsUserInterfaceWidgetPrivate *d; }; #endif // KBIBTEX_GUI_SETTINGSUSERINTERFACEWIDGET_H