diff --git a/autotests/kconfigdialog_unittest.cpp b/autotests/kconfigdialog_unittest.cpp index 28f0c3b..48a3a21 100644 --- a/autotests/kconfigdialog_unittest.cpp +++ b/autotests/kconfigdialog_unittest.cpp @@ -1,297 +1,297 @@ /* This file is part of the KDE libraries Copyright (c) 2012 Albert Astals Cid This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "signaltest.h" static const auto CONFIG_FILE = QStringLiteral("kconfigdialog_unittestrc"); class TextEditUserPropertyWidget : public QWidget { Q_OBJECT // with USER parameter Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged USER true) public: TextEditUserPropertyWidget(QWidget *parent = nullptr) : QWidget(parent) {} void setText(const QString &text) { m_text = text; emit textChanged(m_text); } QString text() const { return m_text; } Q_SIGNALS: void textChanged(const QString &text); private: QString m_text; }; class TextEditNoUserPropertyWidget : public QWidget { Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QString other READ other WRITE setOther NOTIFY otherChanged USER true) public: TextEditNoUserPropertyWidget(QWidget *parent = nullptr) : QWidget(parent) {} void setText(const QString &text) { m_text = text; emit textChanged(m_text); } QString text() const { return m_text; } void setOther(const QString &other) { m_other = other; emit textChanged(m_other); } QString other() const { return m_other; } Q_SIGNALS: void textChanged(const QString &text); void otherChanged(const QString &other); private: QString m_text; QString m_other; }; class ComboBoxPage : public QWidget { public: ComboBoxPage() { colorCombo = new KColorCombo(this); colorCombo->setObjectName(QStringLiteral("kcfg_Color")); colorCombo->setColor(Qt::red); enumCombo = new QComboBox(this); enumCombo->setObjectName(QStringLiteral("kcfg_Enum")); enumCombo->addItems(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C")); textCombo = new QComboBox(this); textCombo->setObjectName(QStringLiteral("kcfg_Text")); textCombo->setEditable(true); textCombo->addItems(QStringList() << QStringLiteral("A") << QStringLiteral("B") << QStringLiteral("C")); numInput = new QSpinBox(this); numInput->setValue(1); numInput->setObjectName(QStringLiteral("kcfg_IntNumInput")); } KColorCombo *colorCombo; QComboBox *enumCombo; QComboBox *textCombo; QSpinBox *numInput; }; class ComboSettings : public KConfigSkeleton { public: ComboSettings() : KConfigSkeleton(CONFIG_FILE) { colorItem = new ItemColor(currentGroup(), QStringLiteral("Color"), color, Qt::white); addItem(colorItem, QStringLiteral("Color")); QList textValues; { ItemEnum::Choice2 choice; choice.name = QStringLiteral("A"); textValues.append(choice); } { ItemEnum::Choice2 choice; choice.name = QStringLiteral("B"); textValues.append(choice); } { ItemEnum::Choice2 choice; choice.name = QStringLiteral("C"); textValues.append(choice); } enumItem = new ItemEnum(currentGroup(), QStringLiteral("Enum"), enumIndex, textValues, 1); addItem(enumItem, QStringLiteral("Enum")); stringItem = new ItemString(currentGroup(), QStringLiteral("Text"), string, QStringLiteral("hh:mm")); addItem(stringItem, QStringLiteral("Text")); intValueItem = new ItemInt(currentGroup(), QStringLiteral("IntNumInput"), intValue, 42); addItem(intValueItem, QStringLiteral("IntNumInput")); } ItemColor *colorItem; QColor color; ItemEnum *enumItem; int enumIndex; ItemString *stringItem; QString string; ItemInt *intValueItem; int intValue; }; class KConfigDialog_UnitTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase() { QStandardPaths::enableTestMode(true); // Leftover configuration breaks combosTest const QString configFile = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, CONFIG_FILE); if (!configFile.isEmpty()) { if (!QFile::remove(configFile)) { qWarning() << "Could not remove old config file:" << configFile; } } } void test() { ComboSettings *skeleton = new ComboSettings(); - KConfigDialog *dialog = new KConfigDialog(0, QStringLiteral("settings"), skeleton); + KConfigDialog *dialog = new KConfigDialog(nullptr, QStringLiteral("settings"), skeleton); ComboBoxPage *page = new ComboBoxPage(); QCOMPARE(page->colorCombo->color().name(), QColor(Qt::red).name()); QCOMPARE(page->enumCombo->currentIndex(), 0); QCOMPARE(page->textCombo->currentText(), QString("A")); QCOMPARE(page->numInput->value(), 1); dialog->addPage(page, QStringLiteral("General")); QCOMPARE(page->colorCombo->color().name(), QColor(Qt::white).name()); QCOMPARE(page->enumCombo->currentIndex(), 1); QCOMPARE(page->textCombo->currentText(), QLatin1String("hh:mm")); QCOMPARE(page->numInput->value(), 42); page->colorCombo->setColor(Qt::blue); page->enumCombo->setCurrentIndex(2); page->textCombo->setCurrentIndex(2); page->numInput->setValue(2); QDialogButtonBox *buttonBox = dialog->findChild(); - QVERIFY(buttonBox != 0); + QVERIFY(buttonBox != nullptr); buttonBox->button(QDialogButtonBox::Apply)->click(); QCOMPARE(skeleton->colorItem->property().value().name(), QColor(Qt::blue).name()); QCOMPARE(skeleton->enumItem->property().toInt(), 2); QCOMPARE(skeleton->stringItem->property().toString(), QLatin1String("C")); QCOMPARE(skeleton->intValueItem->property().toInt(), 2); delete dialog; delete skeleton; } void testKConfigCompilerSignalsKnownWidget() { QLineEdit *edit = new QLineEdit; testKConfigCompilerSignals(edit, QStringLiteral("settings2")); } void testKConfigCompilerSignalsWithUserProperty() { KConfigDialogManager::changedMap()->insert("TextEditUserPropertyWidget", SIGNAL(textChanged(QString))); TextEditUserPropertyWidget *edit = new TextEditUserPropertyWidget; testKConfigCompilerSignals(edit, QStringLiteral("settings3")); } void testKConfigCompilerSignalsWithoutUserPropertyByMap() { KConfigDialogManager::changedMap()->insert("TextEditNoUserPropertyWidget", SIGNAL(textChanged(QString))); KConfigDialogManager::propertyMap()->insert("TextEditNoUserPropertyWidget", QByteArray("text")); TextEditNoUserPropertyWidget *edit = new TextEditNoUserPropertyWidget; testKConfigCompilerSignals(edit, QStringLiteral("settings4")); } void testKConfigCompilerSignalsWithoutUserPropertyByProperty() { KConfigDialogManager::changedMap()->insert("TextEditNoUserPropertyWidget", SIGNAL(textChanged(QString))); TextEditNoUserPropertyWidget *edit = new TextEditNoUserPropertyWidget; edit->setProperty("kcfg_property", QByteArray("text")); testKConfigCompilerSignals(edit, QStringLiteral("settings5")); } private: template void testKConfigCompilerSignals(T* edit, const QString& configDialogTitle) { const QString defaultValue = QStringLiteral("default value"); const QString changedValue = QStringLiteral("changed value"); const QString someOtherValue = QStringLiteral("some other value"); // set to default to ensure no old stored values make things fail SignalTest::self()->setDefaults(); - KConfigDialog *dialog = new KConfigDialog(0, configDialogTitle, SignalTest::self()); + KConfigDialog *dialog = new KConfigDialog(nullptr, configDialogTitle, SignalTest::self()); QWidget* page = new QWidget; edit->setParent(page); edit->setObjectName(QStringLiteral("kcfg_foo")); edit->setText(QStringLiteral("some text")); QSignalSpy spy(SignalTest::self(), SIGNAL(fooChanged(QString))); QVERIFY(spy.isValid()); // now all the magic happens dialog->addPage(page, QStringLiteral("General")); //check that default value gets loaded QCOMPARE(spy.size(), 0); QCOMPARE(edit->text(), defaultValue); QCOMPARE(SignalTest::foo(), defaultValue); edit->setText(changedValue); // change signal should not be emitted immediately (only on save) QCOMPARE(spy.size(), 0); QCOMPARE(SignalTest::foo(), defaultValue); // should be no change to skeleton QDialogButtonBox *buttonBox = dialog->findChild(); - QVERIFY(buttonBox != 0); + QVERIFY(buttonBox != nullptr); buttonBox->button(QDialogButtonBox::Apply)->click(); // now signal should be emitted QCOMPARE(spy.size(), 1); QVariantList args = spy.last(); QCOMPARE(args.size(), 1); QCOMPARE((QMetaType::Type)args[0].type(), QMetaType::QString); QCOMPARE(args[0].toString(), changedValue); QCOMPARE(SignalTest::foo(), changedValue); // change it to a different value edit->setText(someOtherValue); QCOMPARE(spy.size(), 1); buttonBox->button(QDialogButtonBox::Apply)->click(); // now signal should be emitted QCOMPARE(spy.size(), 2); args = spy.last(); QCOMPARE(args.size(), 1); QCOMPARE((QMetaType::Type)args[0].type(), QMetaType::QString); QCOMPARE(args[0].toString(), someOtherValue); QCOMPARE(SignalTest::foo(), someOtherValue); } }; QTEST_MAIN(KConfigDialog_UnitTest) #include "kconfigdialog_unittest.moc" diff --git a/autotests/krecentfilesactiontest.cpp b/autotests/krecentfilesactiontest.cpp index 1ba100d..045e98c 100644 --- a/autotests/krecentfilesactiontest.cpp +++ b/autotests/krecentfilesactiontest.cpp @@ -1,111 +1,111 @@ /* This file is part of the KDE libraries Copyright (c) 2015 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "krecentfilesactiontest.h" #include #include #include KRecentFilesActionTest::KRecentFilesActionTest(QObject *parent) : QObject(parent) { } KRecentFilesActionTest::~KRecentFilesActionTest() { } QStringList KRecentFilesActionTest::extractActionNames(QMenu *menu) { QStringList ret; foreach (const QAction *action, menu->actions()) { ret.append(action->objectName()); } return ret; } QList KRecentFilesActionTest::extractActionEnableVisibleState(QMenu *menu) { QList ret; foreach (const QAction *action, menu->actions()) { ret.append(action->isEnabled()); ret.append(action->isVisible()); } return ret; } void KRecentFilesActionTest::shouldHaveDefaultValue() { - KRecentFilesAction recentAction(0); + KRecentFilesAction recentAction(nullptr); QVERIFY(recentAction.urls().isEmpty()); QVERIFY(recentAction.menu()); QVERIFY(!recentAction.menu()->actions().isEmpty()); QCOMPARE(recentAction.menu()->actions().count(), 3); QCOMPARE(extractActionNames(recentAction.menu()), QStringList() << QLatin1String("no_entries") << QLatin1String("separator") << QLatin1String("clear_action")); QCOMPARE(extractActionEnableVisibleState(recentAction.menu()), QList() << false << true /*no_entries*/ << false << false /*separator*/ << false << false /*clear_action*/ ); } void KRecentFilesActionTest::shouldAddActionInTop() { - KRecentFilesAction recentAction(0); + KRecentFilesAction recentAction(nullptr); recentAction.addUrl(QUrl(QStringLiteral("http://www.kde.org"))); QList lstAction = recentAction.menu()->actions(); QCOMPARE(lstAction.count(), 4); QCOMPARE(extractActionNames(recentAction.menu()), QStringList() << QString() << QLatin1String("no_entries") << QLatin1String("separator") << QLatin1String("clear_action")); QCOMPARE(extractActionEnableVisibleState(recentAction.menu()), QList() << true << true /* new action*/ << false << false /*no_entries*/ << true << true /*separator*/ << true << true /*clear_action*/ ); } void KRecentFilesActionTest::shouldClearMenu() { - KRecentFilesAction recentAction(0); + KRecentFilesAction recentAction(nullptr); recentAction.addUrl(QUrl(QStringLiteral("http://www.kde.org"))); QList lstAction = recentAction.menu()->actions(); QCOMPARE(lstAction.count(), 4); recentAction.clear(); lstAction = recentAction.menu()->actions(); QCOMPARE(lstAction.count(), 3); QCOMPARE(extractActionNames(recentAction.menu()), QStringList() << QLatin1String("no_entries") << QLatin1String("separator") << QLatin1String("clear_action")); QCOMPARE(extractActionEnableVisibleState(recentAction.menu()), QList() << false << true /*no_entries*/ << false << false /*separator*/ << false << false /*clear_action*/ ); } QTEST_MAIN(KRecentFilesActionTest) diff --git a/autotests/krecentfilesactiontest.h b/autotests/krecentfilesactiontest.h index f09bf63..643bf80 100644 --- a/autotests/krecentfilesactiontest.h +++ b/autotests/krecentfilesactiontest.h @@ -1,43 +1,43 @@ /* This file is part of the KDE libraries Copyright (c) 2015 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KRECENTFILESACTIONTEST_H #define KRECENTFILESACTIONTEST_H #include class QMenu; class KRecentFilesActionTest : public QObject { Q_OBJECT public: - explicit KRecentFilesActionTest(QObject *parent = 0); + explicit KRecentFilesActionTest(QObject *parent = nullptr); ~KRecentFilesActionTest(); private: static QStringList extractActionNames(QMenu *menu); static QList extractActionEnableVisibleState(QMenu *menu); private Q_SLOTS: void shouldHaveDefaultValue(); void shouldAddActionInTop(); void shouldClearMenu(); }; #endif // KRECENTFILESACTIONTEST_H diff --git a/autotests/kstandardactiontest.cpp b/autotests/kstandardactiontest.cpp index 9ff32c7..e2d8751 100644 --- a/autotests/kstandardactiontest.cpp +++ b/autotests/kstandardactiontest.cpp @@ -1,150 +1,150 @@ /* Copyright 2007 Simon Hausmann This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kstandardactiontest.h" #include #include #include "kstandardaction.h" void tst_KStandardAction::shortcutForActionId() { QList stdShortcut = KStandardShortcut::shortcut(KStandardShortcut::Cut); - QAction *cut = KStandardAction::cut(NULL); + QAction *cut = KStandardAction::cut(nullptr); QList actShortcut = cut->shortcuts(); QCOMPARE(cut->property("defaultShortcuts").value >(), actShortcut); QVERIFY(stdShortcut == actShortcut); delete cut; - cut = KStandardAction::create(KStandardAction::Cut, NULL, NULL, NULL); + cut = KStandardAction::create(KStandardAction::Cut, nullptr, nullptr, nullptr); actShortcut = cut->shortcuts(); QVERIFY(stdShortcut == actShortcut); delete cut; } class Receiver : public QObject { Q_OBJECT public: Receiver() : triggered(false) {} bool triggered; QUrl lastUrl; public Q_SLOTS: void onTriggered() { triggered = true; } void onUrlSelected(const QUrl &url) { lastUrl = url; } }; void tst_KStandardAction::testCreateNewStyle() { Receiver receiver; QAction *action1 = KStandardAction::create(KStandardAction::Next, &receiver, &Receiver::onTriggered, &receiver); QVERIFY(!receiver.triggered); action1->trigger(); QVERIFY(receiver.triggered); // check that it works with lambdas as well bool triggered = false; auto onTriggered = [&] { triggered = true; }; QAction *action2 = KStandardAction::create(KStandardAction::Copy, &receiver, onTriggered, &receiver); QVERIFY(!triggered); action2->trigger(); QVERIFY(triggered); // check ConfigureToolbars triggered = false; QAction* action3 = KStandardAction::create(KStandardAction::ConfigureToolbars, &receiver, onTriggered, &receiver); QVERIFY(!triggered); action3->trigger(); // a queued connection should be used here QVERIFY(!triggered); QCoreApplication::processEvents(); QVERIFY(triggered); QUrl expectedUrl = QUrl(QStringLiteral("file:///foo/bar")); KRecentFilesAction *recent = KStandardAction::openRecent(&receiver, &Receiver::onUrlSelected, &receiver); QCOMPARE(receiver.lastUrl, QUrl()); recent->urlSelected(expectedUrl); QCOMPARE(receiver.lastUrl, expectedUrl); // same again with lambda QUrl url; KRecentFilesAction *recent2 = KStandardAction::openRecent(&receiver, [&](const QUrl &u) { url = u; }, &receiver); QCOMPARE(url, QUrl()); recent2->urlSelected(expectedUrl); QCOMPARE(url, expectedUrl); // make sure the asserts don't trigger (action has the correct type) KToggleAction *toggle1 = KStandardAction::showMenubar(&receiver, &Receiver::onTriggered, &receiver); QVERIFY(toggle1); KToggleAction *toggle2 = KStandardAction::showStatusbar(&receiver, &Receiver::onTriggered, &receiver); QVERIFY(toggle2); KToggleFullScreenAction *toggle3 = KStandardAction::fullScreen(&receiver, &Receiver::onTriggered, new QWidget, &receiver); QVERIFY(toggle3); } void tst_KStandardAction::testCreateOldStyle() { Receiver receiver; QAction *action1 = KStandardAction::create(KStandardAction::Next, &receiver, SLOT(onTriggered()), &receiver); QVERIFY(!receiver.triggered); action1->trigger(); QVERIFY(receiver.triggered); // check ConfigureToolbars receiver.triggered = false; QAction* action3 = KStandardAction::create(KStandardAction::ConfigureToolbars, &receiver, SLOT(onTriggered()), &receiver); QVERIFY(!receiver.triggered); action3->trigger(); // a queued connection should be used here QVERIFY(!receiver.triggered); QCoreApplication::processEvents(); QVERIFY(receiver.triggered); QUrl expectedUrl = QUrl(QStringLiteral("file:///foo/bar")); KRecentFilesAction *recent = KStandardAction::openRecent(&receiver, SLOT(onUrlSelected(const QUrl &)), &receiver); QCOMPARE(receiver.lastUrl, QUrl()); recent->urlSelected(expectedUrl); QCOMPARE(receiver.lastUrl, expectedUrl); // make sure the asserts don't trigger (action has the correct type) KToggleAction *toggle1 = KStandardAction::showMenubar(&receiver, SLOT(onTriggered()), &receiver); QVERIFY(toggle1); KToggleAction *toggle2 = KStandardAction::showStatusbar(&receiver, SLOT(onTriggered()), &receiver); QVERIFY(toggle2); KToggleFullScreenAction *toggle3 = KStandardAction::fullScreen(&receiver, SLOT(onTriggered()), new QWidget, &receiver); QVERIFY(toggle3); } QTEST_MAIN(tst_KStandardAction) #include "kstandardactiontest.moc" diff --git a/src/kcmodule.cpp b/src/kcmodule.cpp index db6c966..b6d83a4 100644 --- a/src/kcmodule.cpp +++ b/src/kcmodule.cpp @@ -1,304 +1,304 @@ /* This file is part of the KDE libraries Copyright (c) 2001 Michael Goffioul Copyright (C) 2004 Frans Englich Copyright (C) 2009 Dario Freddi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kcmodule.h" #include #include #include #include #include #include #include #include class KCModulePrivate { public: KCModulePrivate(): _buttons(KCModule::Help | KCModule::Default | KCModule::Apply), - _about(0), + _about(nullptr), _useRootOnlyMessage(false), _firstshow(true), _needsAuthorization(false), _authAction(), _unmanagedWidgetChangeState(false) { } void authStatusChanged(int status); KCModule::Buttons _buttons; const KAboutData *_about; QString _rootOnlyMessage; QList managers; QString _quickHelp; QString m_ExportText; bool _useRootOnlyMessage : 1; bool _firstshow : 1; bool _needsAuthorization : 1; KAuth::Action _authAction; // this member is used to record the state on non-automatically // managed widgets, allowing for mixed KConfigXT-drive and manual // widgets to coexist peacefully and do the correct thing with // the changed(bool) signal bool _unmanagedWidgetChangeState : 1; }; KCModule::KCModule(const KAboutData *aboutData, QWidget *parent, const QVariantList &) : QWidget(parent), d(new KCModulePrivate) { setAboutData(aboutData); } KCModule::KCModule(QWidget *parent, const QVariantList &) : QWidget(parent), d(new KCModulePrivate) { } void KCModule::showEvent(QShowEvent *ev) { if (d->_firstshow) { d->_firstshow = false; QMetaObject::invokeMethod(this, "load", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "changed", Qt::QueuedConnection, Q_ARG(bool, false)); } QWidget::showEvent(ev); } KCModule::Buttons KCModule::buttons() const { return d->_buttons; } void KCModule::setButtons(Buttons buttons) { d->_buttons = buttons; } KConfigDialogManager *KCModule::addConfig(KCoreConfigSkeleton *config, QWidget *widget) { KConfigDialogManager *manager = new KConfigDialogManager(widget, config); manager->setObjectName(objectName()); connect(manager, &KConfigDialogManager::widgetModified, this, &KCModule::widgetChanged); d->managers.append(manager); return manager; } KConfigDialogManager *KCModule::addConfig(KConfigSkeleton *config, QWidget *widget) { KConfigDialogManager *manager = new KConfigDialogManager(widget, config); manager->setObjectName(objectName()); connect(manager, &KConfigDialogManager::widgetModified, this, &KCModule::widgetChanged); d->managers.append(manager); return manager; } void KCModule::setNeedsAuthorization(bool needsAuth) { d->_needsAuthorization = needsAuth; if (needsAuth && d->_about) { d->_authAction = KAuth::Action(QString("org.kde.kcontrol." + d->_about->componentName() + ".save")); d->_needsAuthorization = d->_authAction.isValid(); d->_authAction.setHelperId("org.kde.kcontrol." + d->_about->componentName()); d->_authAction.setParentWidget(this); authStatusChanged(d->_authAction.status()); } else { d->_authAction = KAuth::Action(); } } bool KCModule::needsAuthorization() const { return d->_needsAuthorization; } void KCModule::setAuthAction(const KAuth::Action &action) { if (!d->_authAction.isValid()) { qWarning() << "Auth action" << action.name() << "is invalid"; d->_needsAuthorization = false; return; } d->_authAction = action; d->_needsAuthorization = true; d->_authAction.setParentWidget(this); authStatusChanged(d->_authAction.status()); } KAuth::Action KCModule::authAction() const { return d->_authAction; } void KCModule::authStatusChanged(KAuth::Action::AuthStatus status) { switch (status) { case KAuth::Action::AuthorizedStatus: setUseRootOnlyMessage(false); break; case KAuth::Action::AuthRequiredStatus: setUseRootOnlyMessage(true); setRootOnlyMessage(i18n("You will be asked to authenticate before saving")); break; default: setUseRootOnlyMessage(true); setRootOnlyMessage(i18n("You are not allowed to save the configuration")); break; } qDebug() << useRootOnlyMessage(); } KCModule::~KCModule() { qDeleteAll(d->managers); d->managers.clear(); delete d->_about; delete d; } void KCModule::load() { KConfigDialogManager *manager; Q_FOREACH (manager, d->managers) { manager->updateWidgets(); } emit(changed(false)); } void KCModule::save() { KConfigDialogManager *manager; Q_FOREACH (manager, d->managers) { manager->updateSettings(); } emit(changed(false)); } void KCModule::defaults() { KConfigDialogManager *manager; Q_FOREACH (manager, d->managers) { manager->updateWidgetsDefault(); } } void KCModule::widgetChanged() { emit changed(d->_unmanagedWidgetChangeState || managedWidgetChangeState()); } bool KCModule::managedWidgetChangeState() const { KConfigDialogManager *manager; Q_FOREACH (manager, d->managers) { if (manager->hasChanged()) { return true; } } return false; } void KCModule::unmanagedWidgetChangeState(bool changed) { d->_unmanagedWidgetChangeState = changed; widgetChanged(); } const KAboutData *KCModule::aboutData() const { return d->_about; } void KCModule::setAboutData(const KAboutData *about) { if (about != d->_about) { delete d->_about; d->_about = about; } } void KCModule::setRootOnlyMessage(const QString &message) { d->_rootOnlyMessage = message; emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage); } QString KCModule::rootOnlyMessage() const { return d->_rootOnlyMessage; } void KCModule::setUseRootOnlyMessage(bool on) { d->_useRootOnlyMessage = on; emit rootOnlyMessageChanged(d->_useRootOnlyMessage, d->_rootOnlyMessage); } bool KCModule::useRootOnlyMessage() const { return d->_useRootOnlyMessage; } void KCModule::changed() { emit changed(true); } KAboutData KCModule::componentData() const { return *d->_about; } QString KCModule::exportText() const { return d->m_ExportText; } void KCModule::setExportText(const QString &text) { d->m_ExportText = text; } void KCModule::setQuickHelp(const QString &help) { d->_quickHelp = help; emit(quickHelpChanged()); } QString KCModule::quickHelp() const { return d->_quickHelp; } QList KCModule::configs() const { return d->managers; } diff --git a/src/kcmodule.h b/src/kcmodule.h index 44f0e9c..e5ab3ab 100644 --- a/src/kcmodule.h +++ b/src/kcmodule.h @@ -1,444 +1,444 @@ /* This file is part of the KDE libraries Copyright (c) 1999 Matthias Hoelzer-Kluepfel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KCMODULE_H #define KCMODULE_H #include #include #include #include class QStringList; class KAboutData; class KConfigDialogManager; class KCoreConfigSkeleton; class KConfigSkeleton; class KCModulePrivate; /** * The base class for configuration modules. * * Configuration modules are realized as plugins that are loaded only when * needed. * * The module in principle is a simple widget displaying the * item to be changed. The module has a very small interface. * * All the necessary glue logic and the GUI bells and whistles * are provided by the control center and must not concern * the module author. * * To write a config module, you have to create a library * that contains a factory function like the following: * * \code * #include * * K_PLUGIN_FACTORY(MyKCModuleFactory, registerPlugin() ) * \endcode * * The constructor of the KCModule then looks like this: * \code * YourKCModule::YourKCModule( QWidget* parent ) * : KCModule( parent ) * { * KAboutData *about = new KAboutData( * , i18n( "..." ), * KDE_VERSION_STRING, QString(), KAboutLicense::GPL, * i18n( "Copyright 2006 ..." ) ); * about->addAuthor( i18n(...) ); * setAboutData( about ); * . * . * . * } * \endcode * * If you want to make the KCModule available only conditionally (i.e. show in * the list of available modules only if some test succeeds) then you can use * Hidden in the .desktop file. An example: * \code * Hidden[$e]=$(if test -e /dev/js*; then echo "false"; else echo "true"; fi) * \endcode * The example executes the given code in a shell and uses the stdout output for * the Hidden value (so it's either Hidden=true or Hidden=false). * * See http://techbase.kde.org/Development/Tutorials/KCM_HowTo * for more detailed documentation. * * @author Matthias Hoelzer-Kluepfel */ class KCONFIGWIDGETS_EXPORT KCModule : public QWidget { Q_OBJECT public: /** * An enumeration type for the buttons used by this module. * You should only use Help, Default and Apply. The rest is obsolete. * NoAdditionalButton can be used when we do not want have other button that Ok Cancel * * @see KCModule::buttons @see KCModule::setButtons */ enum Button { NoAdditionalButton = 0, Help = 1, Default = 2, Apply = 4, Export = 8 }; Q_DECLARE_FLAGS(Buttons, Button) /** * Base class for all KControlModules. * * @note do not emit changed signals here, since they are not yet connected * to any slot. * @param aboutData becomes owned by the KCModule */ - explicit KCModule(const KAboutData *aboutData, QWidget *parent = 0, const QVariantList &args = QVariantList()); + explicit KCModule(const KAboutData *aboutData, QWidget *parent = nullptr, const QVariantList &args = QVariantList()); /** * Base class for all KControlModules. * * @note do not emit changed signals here, since they are not yet connected * to any slot. */ - explicit KCModule(QWidget *parent = 0, const QVariantList &args = QVariantList()); + explicit KCModule(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); /** * Destroys the module. */ ~KCModule(); /** * Return a quick-help text. * * This method is called when the module is docked. * The quick-help text should contain a short description of the module and * links to the module's help files. You can use QML formatting tags in the text. * * @note make sure the quick help text gets translated (use i18n()). */ virtual QString quickHelp() const; /** * This is generally only called for the KBugReport. * If you override you should have it return a pointer to a constant. * * * @returns the KAboutData for this module */ virtual const KAboutData *aboutData() const; /** * This sets the KAboutData returned by aboutData() * The about data is now owned by KCModule. */ void setAboutData(const KAboutData *about); /** * Indicate which buttons will be used. * * The return value is a value or'ed together from * the Button enumeration type. * * @see KCModule::setButtons */ Buttons buttons() const; /** * Get the RootOnly message for this module. * * When the module must be run as root, or acts differently * for root and a normal user, it is sometimes useful to * customize the message that appears at the top of the module * when used as a normal user. This function returns this * customized message. If none has been set, a default message * will be used. * * @see KCModule::setRootOnlyMessage */ QString rootOnlyMessage() const; /** * Tell if KControl should show a RootOnly message when run as * a normal user. * * In some cases, the module don't want a RootOnly message to * appear (for example if it has already one). This function * tells KControl if a RootOnly message should be shown * * @see KCModule::setUseRootOnlyMessage */ bool useRootOnlyMessage() const; KAboutData componentData() const; /** * @return a list of @ref KConfigDialogManager's in use, if any. */ QList configs() const; /** * @brief Set if the module's save() method requires authorization to be executed. * * The module can set this property to @c true if it requires authorization. * It will still have to execute the action itself using the KAuth library, so * this method is not technically needed to perform the action, but * using this and/or the setAuthAction() method will ensure that hosting * applications like System Settings or kcmshell behave correctly. * * Called with @c true, this method will set the action to "org.kde.kcontrol.name.save" where * "name" is aboutData()->appName() return value. This default action won't be set if * the aboutData() object is not valid. * * Note that called with @c false, this method will reset the action name set with setAuthAction(). * * @param needsAuth Tells if the module's save() method requires authorization to be executed. */ void setNeedsAuthorization(bool needsAuth); /** * Returns the value previously set with setNeedsAuthorization() or setAuthAction(). By default it's @c false. * * @return @c true if the module's save() method requires authorization, @c false otherwise */ bool needsAuthorization() const; /** * @brief Set if the module's save() method requires authorization to be executed * * It will still have to execute the action itself using the KAuth library, so * this method is not technically needed to perform the action, but * using this method will ensure that hosting * applications like System Settings or kcmshell behave correctly. * * @param action the action that will be used by this KCModule */ void setAuthAction(const KAuth::Action &action); /** * Returns the action previously set with setAuthAction(). By default its an invalid action. * * @return The action that has to be authorized to execute the save() method. */ KAuth::Action authAction() const; /** * Returns the value set by setExportText(); * @deprecated since 5.0, obsolete feature */ KCONFIGWIDGETS_DEPRECATED QString exportText() const; /** * Sets the export QString value, used for exporting data. * @deprecated since 5.0, obsolete feature */ KCONFIGWIDGETS_DEPRECATED void setExportText(const QString &); public Q_SLOTS: /** * Load the configuration data into the module. * * The load method sets the user interface elements of the * module to reflect the current settings stored in the * configuration files. * * This method is invoked whenever the module should read its configuration * (most of the times from a config file) and update the user interface. * This happens when the user clicks the "Reset" button in the control * center, to undo all of his changes and restore the currently valid * settings. It is also called right after construction. */ virtual void load(); /** * Save the configuration data. * * The save method stores the config information as shown * in the user interface in the config files. * * If necessary, this method also updates the running system, * e.g. by restarting applications. This normally does not apply for * KSettings::Dialog modules where the updating is taken care of by * KSettings::Dispatcher. * * save is called when the user clicks "Apply" or "Ok". * * If you use KConfigXT, saving is taken care off automatically and * you do not need to load manually. However, if you for some reason reimplement it and * also are using KConfigXT, you must call this function, otherwise the saving of KConfigXT * options will not work. Call it at the very end of your reimplementation, to avoid * changed() signals getting emitted when you modify widgets. */ virtual void save(); /** * Sets the configuration to sensible default values. * * This method is called when the user clicks the "Default" * button. It should set the display to useful values. * * If you use KConfigXT, you do not have to reimplement this function since * the fetching and settings of default values is done automatically. However, if you * reimplement and also are using KConfigXT, remember to call the base function at the * very end of your reimplementation. */ virtual void defaults(); protected: /** * Adds a KCoreConfigskeleton @p config to watch the widget @p widget * * This function is useful if you need to handle multiple configuration files. * * @return a pointer to the KCoreConfigDialogManager in use * @param config the KCoreConfigSkeleton to use * @param widget the widget to watch */ KConfigDialogManager *addConfig(KCoreConfigSkeleton *config, QWidget *widget); /** * Adds a KConfigskeleton @p config to watch the widget @p widget * * This function is useful if you need to handle multiple configuration files. * * @return a pointer to the KConfigDialogManager in use * @param config the KConfigSkeleton to use * @param widget the widget to watch */ KConfigDialogManager *addConfig(KConfigSkeleton *config, QWidget *widget); /** * Sets the quick help. */ void setQuickHelp(const QString &help); void showEvent(QShowEvent *ev) Q_DECL_OVERRIDE; friend class KCModuleProxy; Q_SIGNALS: /** * Indicate that the state of the modules contents has changed. * * This signal is emitted whenever the state of the configuration * shown in the module changes. It allows the module container to * keep track of unsaved changes. */ void changed(bool state); /** * Indicate that the module's quickhelp has changed. * * Emit this signal whenever the module's quickhelp changes. * Modules implemented as tabbed dialogs might want to implement * per-tab quickhelp for example. * */ void quickHelpChanged(); /** * Indicate that the module's root message has changed. * * Emits this signal whenever the module's root message changes. * * @since 4.4 * */ void rootOnlyMessageChanged(bool use, QString message); protected Q_SLOTS: /** * Calling this slot is equivalent to emitting changed(true). */ void changed(); /** * A managed widget was changed, the widget settings and the current * settings are compared and a corresponding changed() signal is emitted */ void widgetChanged(); /** * The status of the auth action, if one, has changed */ void authStatusChanged(KAuth::Action::AuthStatus status); protected: /** * Sets the buttons to display. * * Help: shows a "Help" button. * * Default: shows a "Use Defaults" button. * * Apply: in kcontrol this will show an "Apply" and "Reset" button, * in kcmshell this will show an "Ok", "Apply" and "Cancel" button. * * If Apply is not specified, kcmshell will show a "Close" button. * * @see KCModule::buttons */ void setButtons(Buttons btn); /** * Sets the RootOnly message. * * This message will be shown at the top of the module if useRootOnlyMessage is * set. If no message is set, a default one will be used. * * @see KCModule::rootOnlyMessage */ void setRootOnlyMessage(const QString &message); /** * Change whether or not the RootOnly message should be shown. * * Following the value of @p on, the RootOnly message will be * shown or not. * * @see KCModule::useRootOnlyMessage */ void setUseRootOnlyMessage(bool on); /** * Returns the changed state of automatically managed widgets in this dialog */ bool managedWidgetChangeState() const; /** * Call this method when your manually managed widgets change state between * changed and not changed */ void unmanagedWidgetChangeState(bool); private: KCModulePrivate *const d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(KCModule::Buttons) #endif //KCMODULE_H diff --git a/src/kcodecaction.cpp b/src/kcodecaction.cpp index 2e74c2f..2382a88 100644 --- a/src/kcodecaction.cpp +++ b/src/kcodecaction.cpp @@ -1,269 +1,269 @@ /* kcodecaction.cpp Copyright (c) 2003 Jason Keirstead Copyrigth (c) 2006 Michel Hermier Copyright (c) 2007 Nick Shaforostoff ******************************************************************** * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, * * Fifth Floor, Boston, MA 02110-1301 USA * * * ******************************************************************** */ #include "kcodecaction.h" #include #include #include #include #include #include // Acording to http://www.iana.org/assignments/ianacharset-mib // the default/unknown mib value is 2. #define MIB_DEFAULT 2 class Q_DECL_HIDDEN KCodecAction::Private { public: Private(KCodecAction *parent) : q(parent), - defaultAction(0), - currentSubAction(0) + defaultAction(nullptr), + currentSubAction(nullptr) { } void init(bool); void _k_subActionTriggered(QAction *); KCodecAction *q; QAction *defaultAction; QAction *currentSubAction; }; KCodecAction::KCodecAction(QObject *parent, bool showAutoOptions) : KSelectAction(parent) , d(new Private(this)) { d->init(showAutoOptions); } KCodecAction::KCodecAction(const QString &text, QObject *parent, bool showAutoOptions) : KSelectAction(text, parent) , d(new Private(this)) { d->init(showAutoOptions); } KCodecAction::KCodecAction(const QIcon &icon, const QString &text, QObject *parent, bool showAutoOptions) : KSelectAction(icon, text, parent) , d(new Private(this)) { d->init(showAutoOptions); } KCodecAction::~KCodecAction() { delete d; } void KCodecAction::Private::init(bool showAutoOptions) { q->setToolBarMode(MenuMode); defaultAction = q->addAction(i18nc("Encodings menu", "Default")); int i; foreach (const QStringList &encodingsForScript, KCharsets::charsets()->encodingsByScript()) { KSelectAction *tmp = new KSelectAction(encodingsForScript.at(0), q); if (showAutoOptions) { KEncodingProber::ProberType scri = KEncodingProber::proberTypeForName(encodingsForScript.at(0)); if (scri != KEncodingProber::None) { tmp->addAction(i18nc("Encodings menu", "Autodetect"))->setData(QVariant((uint)scri)); tmp->menu()->addSeparator(); } } for (i = 1; i < encodingsForScript.size(); ++i) { tmp->addAction(encodingsForScript.at(i)); } q->connect(tmp, SIGNAL(triggered(QAction*)), q, SLOT(_k_subActionTriggered(QAction*))); tmp->setCheckable(true); q->addAction(tmp); } q->setCurrentItem(0); } int KCodecAction::mibForName(const QString &codecName, bool *ok) const { // FIXME logic is good but code is ugly bool success = false; int mib = MIB_DEFAULT; KCharsets *charsets = KCharsets::charsets(); if (codecName == d->defaultAction->text()) { success = true; } else { QTextCodec *codec = charsets->codecForName(codecName, success); if (!success) { // Maybe we got a description name instead codec = charsets->codecForName(charsets->encodingForName(codecName), success); } if (codec) { mib = codec->mibEnum(); } } if (ok) { *ok = success; } if (success) { return mib; } qWarning() << "Invalid codec name: " << codecName; return MIB_DEFAULT; } QTextCodec *KCodecAction::codecForMib(int mib) const { if (mib == MIB_DEFAULT) { // FIXME offer to change the default codec return QTextCodec::codecForLocale(); } else { return QTextCodec::codecForMib(mib); } } void KCodecAction::actionTriggered(QAction *action) { //we don't want to emit any signals from top-level items //except for the default one if (action == d->defaultAction) { emit triggered(KEncodingProber::Universal); emit defaultItemTriggered(); } } void KCodecAction::Private::_k_subActionTriggered(QAction *action) { if (currentSubAction == action) { return; } currentSubAction = action; bool ok = false; int mib = q->mibForName(action->text(), &ok); if (ok) { emit q->triggered(action->text()); emit q->triggered(q->codecForMib(mib)); } else { if (!action->data().isNull()) { emit q->triggered((KEncodingProber::ProberType) action->data().toUInt()); } } } QTextCodec *KCodecAction::currentCodec() const { return codecForMib(currentCodecMib()); } bool KCodecAction::setCurrentCodec(QTextCodec *codec) { if (!codec) { return false; } int i, j; for (i = 0; i < actions().size(); ++i) { if (actions().at(i)->menu()) { for (j = 0; j < actions().at(i)->menu()->actions().size(); ++j) { if (!j && !actions().at(i)->menu()->actions().at(j)->data().isNull()) { continue; } if (codec == KCharsets::charsets()->codecForName(actions().at(i)->menu()->actions().at(j)->text())) { d->currentSubAction = actions().at(i)->menu()->actions().at(j); d->currentSubAction->trigger(); return true; } } } } return false; } QString KCodecAction::currentCodecName() const { return d->currentSubAction->text(); } bool KCodecAction::setCurrentCodec(const QString &codecName) { return setCurrentCodec(KCharsets::charsets()->codecForName(codecName)); } int KCodecAction::currentCodecMib() const { return mibForName(currentCodecName()); } bool KCodecAction::setCurrentCodec(int mib) { if (mib == MIB_DEFAULT) { return setCurrentAction(d->defaultAction); } else { return setCurrentCodec(codecForMib(mib)); } } KEncodingProber::ProberType KCodecAction::currentProberType() const { return d->currentSubAction->data().isNull() ? KEncodingProber::None : (KEncodingProber::ProberType)d->currentSubAction->data().toUInt(); } bool KCodecAction::setCurrentProberType(KEncodingProber::ProberType scri) { if (scri == KEncodingProber::Universal) { d->currentSubAction = d->defaultAction; d->currentSubAction->trigger(); return true; } int i; for (i = 0; i < actions().size(); ++i) { if (actions().at(i)->menu()) { if (!actions().at(i)->menu()->actions().isEmpty() && !actions().at(i)->menu()->actions().at(0)->data().isNull() && actions().at(i)->menu()->actions().at(0)->data().toUInt() == (uint)scri ) { d->currentSubAction = actions().at(i)->menu()->actions().at(0); d->currentSubAction->trigger(); return true; } } } return false; } #include "moc_kcodecaction.cpp" diff --git a/src/kcodecaction.h b/src/kcodecaction.h index 01c1ebd..a36973a 100644 --- a/src/kcodecaction.h +++ b/src/kcodecaction.h @@ -1,116 +1,116 @@ /* kcodecaction.h Copyright (c) 2003 Jason Keirstead Copyright (c) 2003-2006 Michel Hermier Copyright (c) 2007 Nick Shaforostoff ******************************************************************** * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library 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 Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the * * Free Software Foundation, Inc., 51 Franklin Street, * * Fifth Floor, Boston, MA 02110-1301 USA * * * ******************************************************************** */ #ifndef KCODECACTION_H #define KCODECACTION_H #include #include #include /** * @short Action for selecting one of several QTextCodec. * * This action shows up a submenu with a list of the available codecs on the system. */ class KCONFIGWIDGETS_EXPORT KCodecAction : public KSelectAction { Q_OBJECT Q_PROPERTY(QString codecName READ currentCodecName WRITE setCurrentCodec) Q_PROPERTY(int codecMib READ currentCodecMib) public: explicit KCodecAction(QObject *parent, bool showAutoOptions = false); KCodecAction(const QString &text, QObject *parent, bool showAutoOptions = false); KCodecAction(const QIcon &icon, const QString &text, QObject *parent, bool showAutoOptions = false); virtual ~KCodecAction(); public: - int mibForName(const QString &codecName, bool *ok = 0) const; + int mibForName(const QString &codecName, bool *ok = nullptr) const; QTextCodec *codecForMib(int mib) const; QTextCodec *currentCodec() const; bool setCurrentCodec(QTextCodec *codec); QString currentCodecName() const; bool setCurrentCodec(const QString &codecName); int currentCodecMib() const; bool setCurrentCodec(int mib); /** * Applicable only if showAutoOptions in c'tor was true * * @returns KEncodingProber::None if specific encoding is selected, not autodetection, otherwise... you know it! */ KEncodingProber::ProberType currentProberType() const; /** * Applicable only if showAutoOptions in c'tor was true * * KEncodingProber::Universal means 'Default' item */ bool setCurrentProberType(KEncodingProber::ProberType); Q_SIGNALS: /** * Specific (proper) codec was selected * * Note that triggered(const QString&) is emitted too (as defined in KSelectAction) */ void triggered(QTextCodec *codec); /** * Autodetection has been selected. * emits KEncodingProber::Universal if Default was selected. * * Applicable only if showAutoOptions in c'tor was true */ void triggered(KEncodingProber::ProberType); /** * If showAutoOptions==true, then better handle triggered(KEncodingProber::ProberType) signal */ void defaultItemTriggered(); protected Q_SLOTS: void actionTriggered(QAction *) Q_DECL_OVERRIDE; protected: using KSelectAction::triggered; private: class Private; Private *const d; Q_PRIVATE_SLOT(d, void _k_subActionTriggered(QAction *)) }; #endif diff --git a/src/kcolorschememanager.h b/src/kcolorschememanager.h index fdbb1ba..2f434c2 100644 --- a/src/kcolorschememanager.h +++ b/src/kcolorschememanager.h @@ -1,123 +1,123 @@ /* This file is part of the KDE project * Copyright (C) 2013 Martin Gräßlin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORSCHEMEMANAGER_H #define KCOLORSCHEMEMANAGER_H #include #include class QAbstractItemModel; class QModelIndex; class QIcon; class KActionMenu; class KColorSchemeManagerPrivate; /** * A small helper to get access to all available color schemes and activating a scheme in the * QApplication. This is useful for applications which want to provide a selection of custom color * schemes to their user. For example it is very common for photo and painting applications to use * a dark color scheme even if the default is a light scheme. * * The KColorSchemeManager provides access to a QAbstractItemModel which holds all the available * schemes. A possible usage looks like the following: * * @code * KColorSchemeManager *schemes = new KColorSchemeManager(this); * QListView *view = new QListView(this); * view->setModel(schemes->model()); * connect(view, &QListView::activated, schemes, &KColorSchemeManager::activateScheme); * @endcode * * In addition the KColorSchemeManager also provides the possibility to create a KActionMenu populated * with all the available color schemes in an action group. If one of the actions is selected the * scheme is applied instantly: * * @code * QToolButton *button = new QToolButton(); * KColorSchemeManager *schemes = new KColorSchemeManager(this); * KActionMenu *menu = schemes->createSchemeSelectionMenu(QStringLiteral("Oxygen"), button); * button->setMenu(menu->menu()); * @endcode * * @since 5.0 */ class KCONFIGWIDGETS_EXPORT KColorSchemeManager : public QObject { Q_OBJECT public: - explicit KColorSchemeManager(QObject *parent = 0); + explicit KColorSchemeManager(QObject *parent = nullptr); virtual ~KColorSchemeManager(); /** * A QAbstractItemModel of all available color schemes. * * The model provides the name of the scheme in Qt::DisplayRole, a preview * in Qt::DelegateRole and the full path to the scheme file in Qt::UserRole. * * @return Model of all available color schemes. */ QAbstractItemModel *model() const; /** * Returns the model index for the scheme with the given @p name. If no such * scheme exists an invalid index is returned. * @see model */ QModelIndex indexForScheme(const QString &name) const; /** * Creates a KActionMenu populated with all the available color schemes. * All actions are in an action group and when one of the actions is triggered the scheme * referenced by this action is activated. * * The color scheme with the same name as @p selectedSchemeName will be checked. If none * of the available color schemes has the same name, no action will be checked. * * The KActionMenu will not be updated in case the installed color schemes change. It's the * task of the user of the KActionMenu to monitor for changes if required. * * @param icon The icon to use for the KActionMenu * @param text The text to use for the KActionMenu * @param selectedSchemeName The name of the color scheme to select * @param parent The parent of the KActionMenu * @return KActionMenu populated with all available color schemes. * @see activateScheme */ KActionMenu *createSchemeSelectionMenu(const QIcon &icon, const QString &text, const QString &selectedSchemeName, QObject *parent); KActionMenu *createSchemeSelectionMenu(const QString &text, const QString &selectedSchemeName, QObject *parent); KActionMenu *createSchemeSelectionMenu(const QString &selectedSchemeName, QObject *parent); public Q_SLOTS: /** * @brief Activates the KColorScheme identified by the provided @p index. * * Installs the KColorScheme as the QApplication's QPalette. * * @param index The index for the KColorScheme to activate. * The index must reference the QAbstractItemModel provided by @link model * @see model() */ void activateScheme(const QModelIndex &index); private: QScopedPointer d; }; #endif diff --git a/src/kcolorschememanager_p.h b/src/kcolorschememanager_p.h index 37dc317..e2e3099 100644 --- a/src/kcolorschememanager_p.h +++ b/src/kcolorschememanager_p.h @@ -1,54 +1,54 @@ /* This file is part of the KDE project * Copyright (C) 2013 Martin Gräßlin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORSCHEMEMANAGER_P_H #define KCOLORSCHEMEMANAGER_P_H #include #include struct KColorSchemeModelData { QString name; QString path; QIcon preview; }; class KColorSchemeModel : public QAbstractListModel { Q_OBJECT public: - explicit KColorSchemeModel(QObject *parent = 0); + explicit KColorSchemeModel(QObject *parent = nullptr); virtual ~KColorSchemeModel(); QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE; private: void init(); QIcon createPreview(const QString &path); QVector m_data; }; class KColorSchemeManagerPrivate { public: KColorSchemeManagerPrivate(); QScopedPointer model; }; #endif diff --git a/src/kconfigdialog.cpp b/src/kconfigdialog.cpp index 910db51..67ff730 100644 --- a/src/kconfigdialog.cpp +++ b/src/kconfigdialog.cpp @@ -1,380 +1,380 @@ /* * This file is part of the KDE libraries * Copyright (C) 2003 Benjamin C Meyer (ben+kdelibs at meyerhome dot net) * Copyright (C) 2003 Waldo Bastian * Copyright (C) 2004 Michael Brade * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kconfigdialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class KConfigDialog::KConfigDialogPrivate { public: KConfigDialogPrivate(KConfigDialog *q, const QString &name, KCoreConfigSkeleton *config) - : q(q), shown(false), manager(0) + : q(q), shown(false), manager(nullptr) { q->setObjectName(name); q->setWindowTitle(i18nc("@title:window", "Configure")); q->setFaceType(List); if (!name.isEmpty()) { openDialogs.insert(name, q); } else { QString genericName; genericName.sprintf("SettingsDialog-%p", static_cast(q)); openDialogs.insert(genericName, q); q->setObjectName(genericName); } QDialogButtonBox *buttonBox = q->buttonBox(); buttonBox->setStandardButtons(QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel | QDialogButtonBox::Help); connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), q, SLOT(updateSettings())); connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), q, SLOT(updateSettings())); connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), q, SLOT(_k_updateButtons())); connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), q, SLOT(updateWidgets())); connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), q, SLOT(updateWidgetsDefault())); connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), q, SLOT(_k_updateButtons())); connect(buttonBox->button(QDialogButtonBox::Help), SIGNAL(clicked()), q, SLOT(showHelp())); connect(q, SIGNAL(pageRemoved(KPageWidgetItem*)), q, SLOT(onPageRemoved(KPageWidgetItem*))); manager = new KConfigDialogManager(q, config); setupManagerConnections(manager); setApplyButtonEnabled(false); } KPageWidgetItem *addPageInternal(QWidget *page, const QString &itemName, const QString &pixmapName, const QString &header); void setupManagerConnections(KConfigDialogManager *manager); void setApplyButtonEnabled(bool enabled); void setRestoreDefaultsButtonEnabled(bool enabled); void _k_updateButtons(); void _k_settingsChangedSlot(); KConfigDialog *q; QString mAnchor; QString mHelpApp; bool shown; KConfigDialogManager *manager; QMap managerForPage; /** * The list of existing dialogs. */ static QHash openDialogs; }; QHash KConfigDialog::KConfigDialogPrivate::openDialogs; KConfigDialog::KConfigDialog(QWidget *parent, const QString &name, KCoreConfigSkeleton *config) : KPageDialog(parent), d(new KConfigDialogPrivate(this, name, config)) { } KConfigDialog::~KConfigDialog() { KConfigDialogPrivate::openDialogs.remove(objectName()); delete d; } KPageWidgetItem *KConfigDialog::addPage(QWidget *page, const QString &itemName, const QString &pixmapName, const QString &header, bool manage) { Q_ASSERT(page); if (!page) { - return 0; + return nullptr; } KPageWidgetItem *item = d->addPageInternal(page, itemName, pixmapName, header); if (manage) { d->manager->addWidget(page); } if (d->shown && manage) { // update the default button if the dialog is shown QPushButton *defaultButton = buttonBox()->button(QDialogButtonBox::RestoreDefaults); if (defaultButton) { bool is_default = defaultButton->isEnabled() && d->manager->isDefault(); defaultButton->setEnabled(!is_default); } } return item; } KPageWidgetItem *KConfigDialog::addPage(QWidget *page, KCoreConfigSkeleton *config, const QString &itemName, const QString &pixmapName, const QString &header) { Q_ASSERT(page); if (!page) { - return 0; + return nullptr; } KPageWidgetItem *item = d->addPageInternal(page, itemName, pixmapName, header); d->managerForPage[page] = new KConfigDialogManager(page, config); d->setupManagerConnections(d->managerForPage[page]); if (d->shown) { // update the default button if the dialog is shown QPushButton *defaultButton = buttonBox()->button(QDialogButtonBox::RestoreDefaults); if (defaultButton) { bool is_default = defaultButton->isEnabled() && d->managerForPage[page]->isDefault(); defaultButton->setEnabled(!is_default); } } return item; } KPageWidgetItem *KConfigDialog::KConfigDialogPrivate::addPageInternal(QWidget *page, const QString &itemName, const QString &pixmapName, const QString &header) { QWidget *frame = new QWidget(q); QVBoxLayout *boxLayout = new QVBoxLayout(frame); boxLayout->setMargin(0); boxLayout->setMargin(0); QScrollArea *scroll = new QScrollArea(q); scroll->setFrameShape(QFrame::NoFrame); scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); scroll->setWidget(page); scroll->setWidgetResizable(true); scroll->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding ); boxLayout->addWidget(scroll); KPageWidgetItem *item = new KPageWidgetItem(frame, itemName); item->setHeader(header); if (!pixmapName.isEmpty()) { item->setIcon(QIcon::fromTheme(pixmapName)); } q->KPageDialog::addPage(item); return item; } void KConfigDialog::KConfigDialogPrivate::setupManagerConnections(KConfigDialogManager *manager) { q->connect(manager, SIGNAL(settingsChanged()), q, SLOT(_k_settingsChangedSlot())); q->connect(manager, SIGNAL(widgetModified()), q, SLOT(_k_updateButtons())); QDialogButtonBox *buttonBox = q->buttonBox(); q->connect(buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), manager, SLOT(updateSettings())); q->connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), manager, SLOT(updateSettings())); q->connect(buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), manager, SLOT(updateWidgets())); q->connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()), manager, SLOT(updateWidgetsDefault())); } void KConfigDialog::KConfigDialogPrivate::setApplyButtonEnabled(bool enabled) { QPushButton *applyButton = q->buttonBox()->button(QDialogButtonBox::Apply); if (applyButton) { applyButton->setEnabled(enabled); } } void KConfigDialog::KConfigDialogPrivate::setRestoreDefaultsButtonEnabled(bool enabled) { QPushButton *restoreDefaultsButton = q->buttonBox()->button(QDialogButtonBox::RestoreDefaults); if (restoreDefaultsButton) { restoreDefaultsButton->setEnabled(enabled); } } void KConfigDialog::onPageRemoved(KPageWidgetItem *item) { QMap::iterator j = d->managerForPage.begin(); while (j != d->managerForPage.end()) { // there is a manager for this page, so remove it if (item->widget()->isAncestorOf(j.key())) { KConfigDialogManager *manager = j.value(); d->managerForPage.erase(j); delete manager; d->_k_updateButtons(); break; } ++j; } } KConfigDialog *KConfigDialog::exists(const QString &name) { QHash::const_iterator it = KConfigDialogPrivate::openDialogs.constFind(name); if (it != KConfigDialogPrivate::openDialogs.constEnd()) { return *it; } - return 0; + return nullptr; } bool KConfigDialog::showDialog(const QString &name) { KConfigDialog *dialog = exists(name); if (dialog) { dialog->show(); } - return (dialog != NULL); + return (dialog != nullptr); } void KConfigDialog::KConfigDialogPrivate::_k_updateButtons() { static bool only_once = false; if (only_once) { return; } only_once = true; QMap::iterator it; bool has_changed = manager->hasChanged() || q->hasChanged(); for (it = managerForPage.begin(); it != managerForPage.end() && !has_changed; ++it) { has_changed |= (*it)->hasChanged(); } setApplyButtonEnabled(has_changed); bool is_default = manager->isDefault() && q->isDefault(); for (it = managerForPage.begin(); it != managerForPage.end() && is_default; ++it) { is_default &= (*it)->isDefault(); } setRestoreDefaultsButtonEnabled(!is_default); emit q->widgetModified(); only_once = false; } void KConfigDialog::KConfigDialogPrivate::_k_settingsChangedSlot() { // Update the buttons _k_updateButtons(); emit q->settingsChanged(q->objectName()); } void KConfigDialog::showEvent(QShowEvent *e) { if (!d->shown) { QMap::iterator it; updateWidgets(); d->manager->updateWidgets(); for (it = d->managerForPage.begin(); it != d->managerForPage.end(); ++it) { (*it)->updateWidgets(); } bool has_changed = d->manager->hasChanged() || hasChanged(); for (it = d->managerForPage.begin(); it != d->managerForPage.end() && !has_changed; ++it) { has_changed |= (*it)->hasChanged(); } d->setApplyButtonEnabled(has_changed); bool is_default = d->manager->isDefault() && isDefault(); for (it = d->managerForPage.begin(); it != d->managerForPage.end() && is_default; ++it) { is_default &= (*it)->isDefault(); } d->setRestoreDefaultsButtonEnabled(!is_default); d->shown = true; } KPageDialog::showEvent(e); } void KConfigDialog::updateSettings() { } void KConfigDialog::updateWidgets() { } void KConfigDialog::updateWidgetsDefault() { } bool KConfigDialog::hasChanged() { return false; } bool KConfigDialog::isDefault() { return true; } void KConfigDialog::updateButtons() { d->_k_updateButtons(); } void KConfigDialog::settingsChangedSlot() { d->_k_settingsChangedSlot(); } void KConfigDialog::setHelp(const QString &anchor, const QString &appname) { d->mAnchor = anchor; d->mHelpApp = appname; } void KConfigDialog::showHelp() { KHelpClient::invokeHelp(d->mAnchor, d->mHelpApp); } #include "moc_kconfigdialog.cpp" diff --git a/src/kconfigdialogmanager.cpp b/src/kconfigdialogmanager.cpp index 4493c1e..e236c29 100644 --- a/src/kconfigdialogmanager.cpp +++ b/src/kconfigdialogmanager.cpp @@ -1,551 +1,551 @@ /* * This file is part of the KDE libraries * Copyright (C) 2003 Benjamin C Meyer (ben+kdelibs at meyerhome dot net) * Copyright (C) 2003 Waldo Bastian * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "kconfigdialogmanager.h" #include #include #include #include #include #include #include #include #include #include typedef QHash MyHash; Q_GLOBAL_STATIC(MyHash, s_propertyMap) Q_GLOBAL_STATIC(MyHash, s_changedMap) class KConfigDialogManagerPrivate { public: KConfigDialogManagerPrivate(KConfigDialogManager *q) : q(q), insideGroupBox(false) { } public: KConfigDialogManager *q; /** * KConfigSkeleton object used to store settings */ KCoreConfigSkeleton *m_conf; /** * Dialog being managed */ QWidget *m_dialog; QHash knownWidget; QHash buddyWidget; QSet allExclusiveGroupBoxes; bool insideGroupBox : 1; bool trackChanges : 1; }; KConfigDialogManager::KConfigDialogManager(QWidget *parent, KCoreConfigSkeleton *conf) : QObject(parent), d(new KConfigDialogManagerPrivate(this)) { d->m_conf = conf; d->m_dialog = parent; init(true); } KConfigDialogManager::KConfigDialogManager(QWidget *parent, KConfigSkeleton *conf) : QObject(parent), d(new KConfigDialogManagerPrivate(this)) { d->m_conf = conf; d->m_dialog = parent; init(true); } KConfigDialogManager::~KConfigDialogManager() { delete d; } void KConfigDialogManager::initMaps() { if (s_propertyMap()->isEmpty()) { s_propertyMap()->insert(QStringLiteral("KButtonGroup"), "current"); s_propertyMap()->insert(QStringLiteral("KColorButton"), "color"); s_propertyMap()->insert(QStringLiteral("KColorCombo"), "color"); } if (s_changedMap()->isEmpty()) { // QT s_changedMap()->insert(QStringLiteral("QCheckBox"), SIGNAL(stateChanged(int))); s_changedMap()->insert(QStringLiteral("QPushButton"), SIGNAL(clicked(bool))); s_changedMap()->insert(QStringLiteral("QRadioButton"), SIGNAL(toggled(bool))); s_changedMap()->insert(QStringLiteral("QGroupBox"), SIGNAL(toggled(bool))); s_changedMap()->insert(QStringLiteral("QComboBox"), SIGNAL(activated(int))); s_changedMap()->insert(QStringLiteral("QDateEdit"), SIGNAL(dateChanged(QDate))); s_changedMap()->insert(QStringLiteral("QTimeEdit"), SIGNAL(timeChanged(QTime))); s_changedMap()->insert(QStringLiteral("QDateTimeEdit"), SIGNAL(dateTimeChanged(QDateTime))); s_changedMap()->insert(QStringLiteral("QDial"), SIGNAL(valueChanged(int))); s_changedMap()->insert(QStringLiteral("QDoubleSpinBox"), SIGNAL(valueChanged(double))); s_changedMap()->insert(QStringLiteral("QLineEdit"), SIGNAL(textChanged(QString))); s_changedMap()->insert(QStringLiteral("QSlider"), SIGNAL(valueChanged(int))); s_changedMap()->insert(QStringLiteral("QSpinBox"), SIGNAL(valueChanged(int))); s_changedMap()->insert(QStringLiteral("QTextEdit"), SIGNAL(textChanged())); s_changedMap()->insert(QStringLiteral("QTextBrowser"), SIGNAL(sourceChanged(QString))); s_changedMap()->insert(QStringLiteral("QPlainTextEdit"), SIGNAL(textChanged())); s_changedMap()->insert(QStringLiteral("QTabWidget"), SIGNAL(currentChanged(int))); // KDE s_changedMap()->insert(QStringLiteral("KComboBox"), SIGNAL(activated(int))); s_changedMap()->insert(QStringLiteral("KFontComboBox"), SIGNAL(activated(int))); s_changedMap()->insert(QStringLiteral("KFontRequester"), SIGNAL(fontSelected(QFont))); s_changedMap()->insert(QStringLiteral("KFontChooser"), SIGNAL(fontSelected(QFont))); s_changedMap()->insert(QStringLiteral("KColorCombo"), SIGNAL(activated(QColor))); s_changedMap()->insert(QStringLiteral("KColorButton"), SIGNAL(changed(QColor))); s_changedMap()->insert(QStringLiteral("KDatePicker"), SIGNAL(dateSelected(QDate))); s_changedMap()->insert(QStringLiteral("KDateWidget"), SIGNAL(changed(QDate))); s_changedMap()->insert(QStringLiteral("KDateTimeWidget"), SIGNAL(valueChanged(QDateTime))); s_changedMap()->insert(QStringLiteral("KEditListWidget"), SIGNAL(changed())); s_changedMap()->insert(QStringLiteral("KListWidget"), SIGNAL(itemSelectionChanged())); s_changedMap()->insert(QStringLiteral("KLineEdit"), SIGNAL(textChanged(QString))); s_changedMap()->insert(QStringLiteral("KRestrictedLine"), SIGNAL(textChanged(QString))); s_changedMap()->insert(QStringLiteral("KTextEdit"), SIGNAL(textChanged())); s_changedMap()->insert(QStringLiteral("KUrlRequester"), SIGNAL(textChanged(QString))); s_changedMap()->insert(QStringLiteral("KUrlComboRequester"), SIGNAL(textChanged(QString))); s_changedMap()->insert(QStringLiteral("KUrlComboBox"), SIGNAL(urlActivated(QUrl))); s_changedMap()->insert(QStringLiteral("KButtonGroup"), SIGNAL(changed(int))); } } QHash *KConfigDialogManager::propertyMap() { initMaps(); return s_propertyMap(); } QHash *KConfigDialogManager::changedMap() { initMaps(); return s_changedMap(); } void KConfigDialogManager::init(bool trackChanges) { initMaps(); d->trackChanges = trackChanges; // Go through all of the children of the widgets and find all known widgets (void) parseChildren(d->m_dialog, trackChanges); } void KConfigDialogManager::addWidget(QWidget *widget) { (void) parseChildren(widget, true); } void KConfigDialogManager::setupWidget(QWidget *widget, KConfigSkeletonItem *item) { QVariant minValue = item->minValue(); if (minValue.isValid()) { // Only q3datetimeedit is using this property we can remove it if we stop supporting Qt3Support if (widget->metaObject()->indexOfProperty("minValue") != -1) { widget->setProperty("minValue", minValue); } if (widget->metaObject()->indexOfProperty("minimum") != -1) { widget->setProperty("minimum", minValue); } } QVariant maxValue = item->maxValue(); if (maxValue.isValid()) { // Only q3datetimeedit is using that property we can remove it if we stop supporting Qt3Support if (widget->metaObject()->indexOfProperty("maxValue") != -1) { widget->setProperty("maxValue", maxValue); } if (widget->metaObject()->indexOfProperty("maximum") != -1) { widget->setProperty("maximum", maxValue); } } if (widget->whatsThis().isEmpty()) { QString whatsThis = item->whatsThis(); if (!whatsThis.isEmpty()) { widget->setWhatsThis(whatsThis); } } if (widget->toolTip().isEmpty()) { QString toolTip = item->toolTip(); if (!toolTip.isEmpty()) { widget->setToolTip(toolTip); } } // If it is a QGroupBox with only autoExclusive buttons // and has no custom property and the config item type // is an integer, assume we want to save the index like we did with // KButtonGroup instead of if it is checked or not QGroupBox *gb = qobject_cast(widget); if (gb && getCustomProperty(gb).isEmpty()) { const KConfigSkeletonItem *item = d->m_conf->findItem(widget->objectName().mid(5)); if (item->property().type() == QVariant::Int) { QObjectList children = gb->children(); children.removeAll(gb->layout()); const QList buttons = gb->findChildren(); if (children.count() == buttons.count()) { bool allAutoExclusive = true; foreach(QAbstractButton *button, buttons) { allAutoExclusive = allAutoExclusive && button->autoExclusive(); } if (allAutoExclusive) { d->allExclusiveGroupBoxes << widget; } } } } if (!item->isEqual(property(widget))) { setProperty(widget, item->property()); } } bool KConfigDialogManager::parseChildren(const QWidget *widget, bool trackChanges) { bool valueChanged = false; const QList listOfChildren = widget->children(); if (listOfChildren.count() == 0) { //?? XXX return valueChanged; } foreach (QObject *object, listOfChildren) { if (!object->isWidgetType()) { continue; // Skip non-widgets } QWidget *childWidget = static_cast(object); QString widgetName = childWidget->objectName(); bool bParseChildren = true; bool bSaveInsideGroupBox = d->insideGroupBox; if (widgetName.startsWith(QLatin1String("kcfg_"))) { // This is one of our widgets! QString configId = widgetName.mid(5); KConfigSkeletonItem *item = d->m_conf->findItem(configId); if (item) { d->knownWidget.insert(configId, childWidget); setupWidget(childWidget, item); if (trackChanges) { if (d->allExclusiveGroupBoxes.contains(childWidget)) { const QList buttons = childWidget->findChildren(); foreach(QAbstractButton *button, buttons) { connect(button, SIGNAL(toggled(bool)), this, SIGNAL(widgetModified())); } } QHash::const_iterator changedIt = s_changedMap()->constFind(childWidget->metaObject()->className()); if (changedIt == s_changedMap()->constEnd()) { // If the class name of the widget wasn't in the monitored widgets map, then look for // it again using the super class name. This fixes a problem with using QtRuby/Korundum // widgets with KConfigXT where 'Qt::Widget' wasn't being seen a the real deal, even // though it was a 'QWidget'. if (childWidget->metaObject()->superClass()) { changedIt = s_changedMap()->constFind(childWidget->metaObject()->superClass()->className()); } else { - changedIt = s_changedMap()->constFind(0); + changedIt = s_changedMap()->constFind(nullptr); } } if (changedIt == s_changedMap()->constEnd()) { qWarning() << "Don't know how to monitor widget '" << childWidget->metaObject()->className() << "' for changes!"; } else { connect(childWidget, *changedIt, this, SIGNAL(widgetModified())); QComboBox *cb = qobject_cast(childWidget); if (cb && cb->isEditable()) connect(cb, SIGNAL(editTextChanged(QString)), this, SIGNAL(widgetModified())); } } QGroupBox *gb = qobject_cast(childWidget); if (!gb) { bParseChildren = false; } else { d->insideGroupBox = true; } } else { qWarning() << "A widget named '" << widgetName << "' was found but there is no setting named '" << configId << "'"; } } else if (QLabel *label = qobject_cast(childWidget)) { QWidget *buddy = label->buddy(); if (!buddy) { continue; } QString buddyName = buddy->objectName(); if (buddyName.startsWith(QLatin1String("kcfg_"))) { // This is one of our widgets! QString configId = buddyName.mid(5); d->buddyWidget.insert(configId, childWidget); } } //kf5: commented out to reduce debug output // #ifndef NDEBUG // else if (!widgetName.isEmpty() && trackChanges) // { // QHash::const_iterator changedIt = s_changedMap()->constFind(childWidget->metaObject()->className()); // if (changedIt != s_changedMap()->constEnd()) // { // if ((!d->insideGroupBox || !qobject_cast(childWidget)) && // !qobject_cast(childWidget) &&!qobject_cast(childWidget) ) // qDebug() << "Widget '" << widgetName << "' (" << childWidget->metaObject()->className() << ") remains unmanaged."; // } // } // #endif if (bParseChildren) { // this widget is not known as something we can store. // Maybe we can store one of its children. valueChanged |= parseChildren(childWidget, trackChanges); } d->insideGroupBox = bSaveInsideGroupBox; } return valueChanged; } void KConfigDialogManager::updateWidgets() { bool changed = false; bool bSignalsBlocked = signalsBlocked(); blockSignals(true); QWidget *widget; QHashIterator it(d->knownWidget); while (it.hasNext()) { it.next(); widget = it.value(); KConfigSkeletonItem *item = d->m_conf->findItem(it.key()); if (!item) { qWarning() << "The setting '" << it.key() << "' has disappeared!"; continue; } if (!item->isEqual(property(widget))) { setProperty(widget, item->property()); // qDebug() << "The setting '" << it.key() << "' [" << widget->className() << "] has changed"; changed = true; } if (item->isImmutable()) { widget->setEnabled(false); - QWidget *buddy = d->buddyWidget.value(it.key(), 0); + QWidget *buddy = d->buddyWidget.value(it.key(), nullptr); if (buddy) { buddy->setEnabled(false); } } } blockSignals(bSignalsBlocked); if (changed) { QTimer::singleShot(0, this, SIGNAL(widgetModified())); } } void KConfigDialogManager::updateWidgetsDefault() { bool bUseDefaults = d->m_conf->useDefaults(true); updateWidgets(); d->m_conf->useDefaults(bUseDefaults); } void KConfigDialogManager::updateSettings() { bool changed = false; QWidget *widget; QHashIterator it(d->knownWidget); while (it.hasNext()) { it.next(); widget = it.value(); KConfigSkeletonItem *item = d->m_conf->findItem(it.key()); if (!item) { qWarning() << "The setting '" << it.key() << "' has disappeared!"; continue; } QVariant fromWidget = property(widget); if (!item->isEqual(fromWidget)) { item->setProperty(fromWidget); changed = true; } } if (changed) { d->m_conf->save(); emit settingsChanged(); } } QByteArray KConfigDialogManager::getUserProperty(const QWidget *widget) const { if (!s_propertyMap()->contains(widget->metaObject()->className())) { const QMetaObject *metaObject = widget->metaObject(); const QMetaProperty user = metaObject->userProperty(); if (user.isValid()) { s_propertyMap()->insert(widget->metaObject()->className(), user.name()); //qDebug() << "class name: '" << widget->metaObject()->className() //<< " 's USER property: " << metaProperty.name() << endl; } else { return QByteArray(); //no USER property } } const QComboBox *cb = qobject_cast(widget); if (cb) { const char *qcomboUserPropertyName = cb->QComboBox::metaObject()->userProperty().name(); const int qcomboUserPropertyIndex = qcomboUserPropertyName ? cb->QComboBox::metaObject()->indexOfProperty(qcomboUserPropertyName) : -1; const char *widgetUserPropertyName = widget->metaObject()->userProperty().name(); const int widgetUserPropertyIndex = widgetUserPropertyName ? cb->metaObject()->indexOfProperty(widgetUserPropertyName) : -1; if (qcomboUserPropertyIndex == widgetUserPropertyIndex) { return QByteArray(); // use the q/kcombobox special code } } return s_propertyMap()->value(widget->metaObject()->className()); } QByteArray KConfigDialogManager::getCustomProperty(const QWidget *widget) const { QVariant prop(widget->property("kcfg_property")); if (prop.isValid()) { if (!prop.canConvert(QVariant::ByteArray)) { qWarning() << "kcfg_property on" << widget->metaObject()->className() << "is not of type ByteArray"; } else { return prop.toByteArray(); } } return QByteArray(); } void KConfigDialogManager::setProperty(QWidget *w, const QVariant &v) { if (d->allExclusiveGroupBoxes.contains(w)) { const QList buttons = w->findChildren(); if (v.toInt() < buttons.count()) { buttons[v.toInt()]->setChecked(true); } return; } QByteArray userproperty = getCustomProperty(w); if (userproperty.isEmpty()) { userproperty = getUserProperty(w); } if (userproperty.isEmpty()) { QComboBox *cb = qobject_cast(w); if (cb) { if (cb->isEditable()) { int i = cb->findText(v.toString()); if (i != -1) { cb->setCurrentIndex(i); } else { cb->setEditText(v.toString()); } } else { cb->setCurrentIndex(v.toInt()); } return; } } if (userproperty.isEmpty()) { qWarning() << w->metaObject()->className() << " widget not handled!"; return; } w->setProperty(userproperty, v); } QVariant KConfigDialogManager::property(QWidget *w) const { if (d->allExclusiveGroupBoxes.contains(w)) { const QList buttons = w->findChildren(); for (int i = 0; i < buttons.count(); ++i) { if (buttons[i]->isChecked()) return i; } return -1; } QByteArray userproperty = getCustomProperty(w); if (userproperty.isEmpty()) { userproperty = getUserProperty(w); } if (userproperty.isEmpty()) { QComboBox *cb = qobject_cast(w); if (cb) { if (cb->isEditable()) { return QVariant(cb->currentText()); } else { return QVariant(cb->currentIndex()); } } } if (userproperty.isEmpty()) { qWarning() << w->metaObject()->className() << " widget not handled!"; return QVariant(); } return w->property(userproperty); } bool KConfigDialogManager::hasChanged() const { QWidget *widget; QHashIterator it(d->knownWidget); while (it.hasNext()) { it.next(); widget = it.value(); KConfigSkeletonItem *item = d->m_conf->findItem(it.key()); if (!item) { qWarning() << "The setting '" << it.key() << "' has disappeared!"; continue; } if (!item->isEqual(property(widget))) { // qDebug() << "Widget for '" << it.key() << "' has changed."; return true; } } return false; } bool KConfigDialogManager::isDefault() const { bool bUseDefaults = d->m_conf->useDefaults(true); bool result = !hasChanged(); d->m_conf->useDefaults(bUseDefaults); return result; } diff --git a/src/kconfigviewstatesaver.h b/src/kconfigviewstatesaver.h index 1c7c6d9..9ddcaba 100644 --- a/src/kconfigviewstatesaver.h +++ b/src/kconfigviewstatesaver.h @@ -1,28 +1,28 @@ #ifndef KCONFIGVIEWSTATESAVER_H #define KCONFIGVIEWSTATESAVER_H #include "kviewstateserializer.h" #include "kconfigwidgets_export.h" class KConfigGroup; class KCONFIGWIDGETS_EXPORT KConfigViewStateSaver : public KViewStateSerializer { Q_OBJECT public: - explicit KConfigViewStateSaver(QObject *parent = 0); + explicit KConfigViewStateSaver(QObject *parent = nullptr); /** Saves the state to the @p configGroup */ void saveState(KConfigGroup &configGroup); /** Restores the state from the @p configGroup */ void restoreState(const KConfigGroup &configGroup); }; #endif diff --git a/src/klanguagebutton.cpp b/src/klanguagebutton.cpp index d871d6f..4e0fb86 100644 --- a/src/klanguagebutton.cpp +++ b/src/klanguagebutton.cpp @@ -1,287 +1,287 @@ /* * Copyright (c) 1999-2003 Hans Petter Bieker * (c) 2007 David Jarvie * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "klanguagebutton.h" #include #include #include #include #include #include #include #include #include static void checkInsertPos(QMenu *popup, const QString &str, int &index) { if (index != -1) { return; } int a = 0; const QList actions = popup->actions(); int b = actions.count(); while (a < b) { int w = (a + b) / 2; QAction *ac = actions[ w ]; int j = str.localeAwareCompare(ac->text()); if (j > 0) { a = w + 1; } else { b = w; } } index = a; // it doesn't really matter ... a == b here. Q_ASSERT(a == b); } class KLanguageButtonPrivate { public: KLanguageButtonPrivate(KLanguageButton *parent); ~KLanguageButtonPrivate() { delete button; delete popup; } void setCurrentItem(QAction *); void clear(); QAction *findAction(const QString &data) const; QPushButton *button; QStringList ids; QMenu *popup; QString current; QString locale; bool staticText : 1; bool showCodes : 1; }; KLanguageButton::KLanguageButton(QWidget *parent) : QWidget(parent), d(new KLanguageButtonPrivate(this)) { } KLanguageButton::KLanguageButton(const QString &text, QWidget *parent) : QWidget(parent), d(new KLanguageButtonPrivate(this)) { setText(text); } KLanguageButtonPrivate::KLanguageButtonPrivate(KLanguageButton *parent) : button(new QPushButton(parent)), popup(new QMenu(parent)), locale(QLocale::system().name()), staticText(false), showCodes(false) { QHBoxLayout *layout = new QHBoxLayout(parent); layout->setMargin(0); layout->addWidget(button); parent->setFocusProxy(button); parent->setFocusPolicy(button->focusPolicy()); button->setMenu(popup); QObject::connect(popup, SIGNAL(triggered(QAction*)), parent, SLOT(slotTriggered(QAction*))); QObject::connect(popup, SIGNAL(hovered(QAction*)), parent, SLOT(slotHovered(QAction*))); } KLanguageButton::~KLanguageButton() { delete d; } void KLanguageButton::setText(const QString &text) { d->staticText = true; d->button->setText(text); } void KLanguageButton::setLocale(const QString &locale) { d->locale = locale; } void KLanguageButton::showLanguageCodes(bool show) { d->showCodes = show; } void KLanguageButton::insertLanguage(const QString &languageCode, const QString &name, int index) { QString text; bool showCodes = d->showCodes; if (name.isEmpty()) { text = languageCode; QLocale locale(languageCode); if (locale != QLocale::c()) { text = locale.nativeLanguageName(); } else { showCodes = false; } } else { text = name; } if (showCodes) { text += QLatin1String(" (") + languageCode + QLatin1Char(')'); } checkInsertPos(d->popup, text, index); QAction *a = new QAction(QIcon(), text, this); a->setData(languageCode); if (index >= 0 && index < d->popup->actions().count() - 1) { d->popup->insertAction(d->popup->actions()[index], a); } else { d->popup->addAction(a); } d->ids.append(languageCode); } void KLanguageButton::insertSeparator(int index) { if (index >= 0 && index < d->popup->actions().count() - 1) { d->popup->insertSeparator(d->popup->actions()[index]); } else { d->popup->addSeparator(); } } void KLanguageButton::loadAllLanguages() { QStringList langlist; const QStringList localeDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("locale"), QStandardPaths::LocateDirectory); Q_FOREACH (const QString &localeDir, localeDirs) { const QStringList entries = QDir(localeDir).entryList(QDir::Dirs); Q_FOREACH (const QString &d, entries) { const QString entryFile = localeDir + '/' + d + "/kf5_entry.desktop"; if (QFile::exists(entryFile)) { langlist.append(entryFile); } } } langlist.sort(); for (int i = 0, count = langlist.count(); i < count; ++i) { QString fpath = langlist[i].left(langlist[i].length() - 14); QString code = fpath.mid(fpath.lastIndexOf('/') + 1); KConfig entry(langlist[i], KConfig::SimpleConfig); KConfigGroup group(&entry, "KCM Locale"); QString name = group.readEntry("Name", i18n("without name")); insertLanguage(code, name); } setCurrentItem(d->locale); } void KLanguageButton::slotTriggered(QAction *a) { //qDebug() << "slotTriggered" << index; if (!a) { return; } d->setCurrentItem(a); // Forward event from popup menu as if it was emitted from this widget: emit activated(d->current); } void KLanguageButton::slotHovered(QAction *a) { //qDebug() << "slotHovered" << index; emit highlighted(a->data().toString()); } int KLanguageButton::count() const { return d->ids.count(); } void KLanguageButton::clear() { d->clear(); } void KLanguageButtonPrivate::clear() { ids.clear(); popup->clear(); if (!staticText) { button->setText(QString()); } } bool KLanguageButton::contains(const QString &languageCode) const { return d->ids.contains(languageCode); } QString KLanguageButton::current() const { return d->current.isEmpty() ? QStringLiteral("en") : d->current; } QAction *KLanguageButtonPrivate::findAction(const QString &data) const { Q_FOREACH (QAction *a, popup->actions()) { if (!a->data().toString().compare(data)) { return a; } } - return 0; + return nullptr; } void KLanguageButton::setCurrentItem(const QString &languageCode) { if (!d->ids.count()) { return; } QAction *a; if (d->ids.indexOf(languageCode) < 0) { a = d->findAction(d->ids[0]); } else { a = d->findAction(languageCode); } if (a) { d->setCurrentItem(a); } } void KLanguageButtonPrivate::setCurrentItem(QAction *a) { if (!a->data().isValid()) { return; } current = a->data().toString(); if (!staticText) { button->setText(a->text()); } } diff --git a/src/klanguagebutton.h b/src/klanguagebutton.h index 4b8e501..fa5566f 100644 --- a/src/klanguagebutton.h +++ b/src/klanguagebutton.h @@ -1,175 +1,175 @@ /* * klangbutton.h - Button with language selection drop down menu. * Derived from the KLangCombo class by Hans Petter Bieker. * * Copyright (c) 1999-2003 Hans Petter Bieker * (c) 2001 Martijn Klingens * (c) 2007 David Jarvie * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KLANGUAGEBUTTON_H #define KLANGUAGEBUTTON_H #include "kconfigwidgets_export.h" #include class QAction; class KLanguageButtonPrivate; /** * KLanguageButton is a pushbutton which allows a language to be selected from * a popup list. * * Languages are identified by their ISO 639-1 codes, e.g. en, pt_BR. * * \image html klanguagebutton.png "KDE Language Selection Widget" * * @author Hans Petter Bieker , Martijn Klingens , * David Jarvie */ class KCONFIGWIDGETS_EXPORT KLanguageButton : public QWidget { Q_OBJECT public: /** * Constructs a button whose text is determined by the current language * in the popup list. * * @param parent the parent of the button */ - explicit KLanguageButton(QWidget *parent = 0); + explicit KLanguageButton(QWidget *parent = nullptr); /** * Constructs a button with static text. * * @param text the text of the button * @param parent the parent of the button */ - explicit KLanguageButton(const QString &text, QWidget *parent = 0); + explicit KLanguageButton(const QString &text, QWidget *parent = nullptr); /** * Deconstructor */ virtual ~KLanguageButton(); /** * Sets the locale to display language names. By default, QLocale::system().name() is used. * * @param locale locale to use */ void setLocale(const QString &locale); /** * Sets a static button text. * * @param text button text */ void setText(const QString &text); /** * Specifies whether language codes should be shown alongside language names * in the popup. Calling this method does not affect any previously * inserted language texts, so it should normally be called before * populating the list. * * @param show true to show codes, false to hide codes */ void showLanguageCodes(bool show); /** * Load all known languages into the popup list. * The current language in the list is set to the default language for the * current locale (as modified by setLocale()). */ void loadAllLanguages(); /** * Inserts a language into the combo box. * Normally the display name of the language is obtained automatically, but * if either the language code does not exist, or there are special display * requirements, the name of the language can be specified in @p name. * * @param languageCode the code for the language * @param name language name. If empty, the name is obtained automatically. * @param index the insertion position, or -1 to insert in alphabetical order */ void insertLanguage(const QString &languageCode, const QString &name = QString(), int index = -1); /** * Inserts a separator item into the combo box. A negative index will append the item. * * @param index the insertion position */ void insertSeparator(int index = -1); /** * Returns the number of items in the combo box. */ int count() const; /** * Removes all combobox items. */ void clear(); /** * Returns the language code of the combobox's current item. * * @return the current item's language code */ QString current() const; /** * Checks whether the specified language is in the popup list. * * @param languageCode the language's code * @return true if in the list */ bool contains(const QString &languageCode) const; /** * Sets a given language to be the current item. * * @param languageCode the language's code */ void setCurrentItem(const QString &languageCode); Q_SIGNALS: /** * This signal is emitted when a new item is activated. * * @param languageCode code of the activated language */ void activated(const QString &languageCode); /** * This signal is emitted when a new item is highlighted. * * @param languageCode code of the highlighted language */ void highlighted(const QString &languageCode); private Q_SLOTS: void slotTriggered(QAction *); void slotHovered(QAction *); private: KLanguageButtonPrivate *const d; }; #endif diff --git a/src/krecentfilesaction_p.h b/src/krecentfilesaction_p.h index 2c690a7..f5c0c06 100644 --- a/src/krecentfilesaction_p.h +++ b/src/krecentfilesaction_p.h @@ -1,65 +1,65 @@ /* This file is part of the KDE libraries Copyright (C) 1999 Reginald Stadlbauer (C) 1999 Simon Hausmann (C) 2000 Nicolas Hadacek (C) 2000 Kurt Granroth (C) 2000 Michael Koch (C) 2001 Holger Freyther (C) 2002 Ellis Whitehead (C) 2002 Joseph Wenninger (C) 2003 Andras Mantia (C) 2005-2006 Hamish Rodda This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KRECENTFILESACTION_P_H #define KRECENTFILESACTION_P_H #include "krecentfilesaction.h" class KRecentFilesActionPrivate { Q_DECLARE_PUBLIC(KRecentFilesAction) public: KRecentFilesActionPrivate(KRecentFilesAction *parent) : q_ptr(parent) { m_maxItems = 10; - m_noEntriesAction = 0; - clearSeparator = 0; - clearAction = 0; + m_noEntriesAction = nullptr; + clearSeparator = nullptr; + clearAction = nullptr; } virtual ~KRecentFilesActionPrivate() { } void init(); void _k_urlSelected(QAction *); int m_maxItems; QMap m_shortNames; QMap m_urls; QAction *m_noEntriesAction; QAction *clearSeparator; QAction *clearAction; KRecentFilesAction *q_ptr; }; #endif // KRECENTFILESACTION_P_H diff --git a/src/kstandardaction.cpp b/src/kstandardaction.cpp index cbed2d9..6e5bba7 100644 --- a/src/kstandardaction.cpp +++ b/src/kstandardaction.cpp @@ -1,716 +1,716 @@ /* This file is part of the KDE libraries Copyright (C) 1999,2000 Kurt Granroth This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kstandardaction.h" #include "kstandardaction_p.h" #include "moc_kstandardaction_p.cpp" #include #include #include #include #include #include #include #include #include #include #include "kdualaction.h" #include "kpastetextaction.h" namespace KStandardAction { AutomaticAction::AutomaticAction(const QIcon &icon, const QString &text, const QList &shortcut, const char *slot, QObject *parent) : QAction(parent) { setText(text); setIcon(icon); setShortcuts(shortcut); setProperty("defaultShortcuts", QVariant::fromValue(shortcut)); connect(this, SIGNAL(triggered()), this, slot); } QStringList stdNames() { return internal_stdNames(); } QList actionIds() { QList result; for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) { result.append(g_rgActionInfo[i].id); } return result; } KCONFIGWIDGETS_EXPORT KStandardShortcut::StandardShortcut shortcutForActionId(StandardAction id) { const KStandardActionInfo *pInfo = infoPtr(id); return (pInfo) ? pInfo->idAccel : KStandardShortcut::AccelNone; } class ShowMenubarActionFilter : public QObject { public: ShowMenubarActionFilter(QAction *parent) : QObject(parent) , wasNative(false) , wasChecked(false) , wasVisible(false) { } bool eventFilter(QObject * /*watched*/, QEvent *e) override { if (e->type() == QEvent::Show) { updateAction(); } return false; } void updateAction() { bool allMenuBarsNative = true; foreach(QWidget *w, qApp->topLevelWidgets()) { QMainWindow *mw = qobject_cast(w); if (mw) { mw->installEventFilter(this); // this is just in case a new main window appeared // if we were filtering it already it is almost a noop if (mw->layout() && mw->layout()->menuBar()) { QMenuBar *mb = qobject_cast(mw->layout()->menuBar()); if (mb && !mb->isNativeMenuBar()) { allMenuBarsNative = false; } } } } QAction *showMenubarAction = static_cast(parent()); if (allMenuBarsNative && !wasNative) { wasNative = true; wasChecked = showMenubarAction->isChecked(); wasVisible = showMenubarAction->isVisible(); showMenubarAction->setChecked(true); showMenubarAction->setVisible(false); } else if (!allMenuBarsNative && wasNative) { showMenubarAction->setChecked(wasChecked); showMenubarAction->setVisible(wasVisible); } } bool wasNative; bool wasChecked; bool wasVisible; }; QAction* _k_createInternal(StandardAction id, QObject *parent) { static bool stdNamesInitialized = false; if (!stdNamesInitialized) { KAcceleratorManager::addStandardActionNames(stdNames()); stdNamesInitialized = true; } - QAction *pAction = 0; + QAction *pAction = nullptr; const KStandardActionInfo *pInfo = infoPtr(id); // qDebug() << "KStandardAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << " )"; // ellis if (pInfo) { QString sLabel, iconName = pInfo->psIconName; switch (id) { case Back: sLabel = i18nc("go back", "&Back"); if (QApplication::isRightToLeft()) { iconName = QStringLiteral("go-next"); } break; case Forward: sLabel = i18nc("go forward", "&Forward"); if (QApplication::isRightToLeft()) { iconName = QStringLiteral("go-previous"); } break; case Home: sLabel = i18nc("home page", "&Home"); break; case Help: sLabel = i18nc("show help", "&Help"); break; case Preferences: case AboutApp: case HelpContents: { QString appDisplayName = QGuiApplication::applicationDisplayName(); if (appDisplayName.isEmpty()) { appDisplayName = QCoreApplication::applicationName(); } sLabel = i18n(pInfo->psLabel, appDisplayName); } break; default: sLabel = i18n(pInfo->psLabel); } if (QApplication::isRightToLeft()) { switch (id) { case Prior: iconName = QStringLiteral("go-next-view-page"); break; case Next: iconName = QStringLiteral("go-previous-view-page"); break; case FirstPage: iconName = QStringLiteral("go-last-view-page"); break; case LastPage: iconName = QStringLiteral("go-first-view-page"); break; case DocumentBack: iconName = QStringLiteral("go-next"); break; case DocumentForward: iconName = QStringLiteral("go-previous"); break; default: break; } } QIcon icon = iconName.isEmpty() ? QIcon() : QIcon::fromTheme(iconName); switch (id) { case OpenRecent: pAction = new KRecentFilesAction(parent); break; case ShowMenubar: { pAction = new KToggleAction(parent); pAction->setWhatsThis(i18n("Show Menubar

" "Shows the menubar again after it has been hidden

")); pAction->setChecked(true); ShowMenubarActionFilter *mf = new ShowMenubarActionFilter(pAction); foreach(QWidget *w, qApp->topLevelWidgets()) { if (qobject_cast(w)) { w->installEventFilter(mf); } } mf->updateAction(); break; } case ShowToolbar: pAction = new KToggleAction(parent); pAction->setChecked(true); break; case ShowStatusbar: pAction = new KToggleAction(parent); pAction->setWhatsThis(i18n("Show Statusbar

" "Shows the statusbar, which is the bar at the bottom of the window used for status information.

")); pAction->setChecked(true); break; case FullScreen: pAction = new KToggleFullScreenAction(parent); pAction->setCheckable(true); break; case PasteText: pAction = new KPasteTextAction(parent); break; // Same as default, but with the app icon case AboutApp: { pAction = new QAction(parent); icon = qApp->windowIcon(); if (icon.isNull()) { const KAboutData data = KAboutData::applicationData(); if (!data.programIconName().isEmpty()) { icon = QIcon::fromTheme(data.programIconName()); } } break; } default: pAction = new QAction(parent); break; } // Set the text before setting the MenuRole, as on OS X setText will do some heuristic role guessing. // This ensures user menu items get the intended role out of the list below. pAction->setText(sLabel); switch (id) { case Quit: pAction->setMenuRole(QAction::QuitRole); break; case Preferences: pAction->setMenuRole(QAction::PreferencesRole); break; case AboutApp: pAction->setMenuRole(QAction::AboutRole); break; default: pAction->setMenuRole(QAction::NoRole); break; } if (pInfo->psToolTip) { pAction->setToolTip(i18n(pInfo->psToolTip)); } pAction->setIcon(icon); QList cut = KStandardShortcut::shortcut(pInfo->idAccel); if (!cut.isEmpty()) { // emulate KActionCollection::setDefaultShortcuts to allow the use of "configure shortcuts" pAction->setShortcuts(cut); pAction->setProperty("defaultShortcuts", QVariant::fromValue(cut)); } pAction->setObjectName(pInfo->psName); } if (pAction && parent && parent->inherits("KActionCollection")) { QMetaObject::invokeMethod(parent, "addAction", Q_ARG(QString, pAction->objectName()), Q_ARG(QAction *, pAction)); } return pAction; } QAction *create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent) { QAction* pAction = _k_createInternal(id, parent); if (recvr && slot) { if (id == OpenRecent) { // FIXME QAction port: probably a good idea to find a cleaner way to do this // Open Recent is a special case - provide the selected URL QObject::connect(pAction, SIGNAL(urlSelected(QUrl)), recvr, slot); } else if (id == ConfigureToolbars) { // #200815 QObject::connect(pAction, SIGNAL(triggered(bool)), recvr, slot, Qt::QueuedConnection); } else { QObject::connect(pAction, SIGNAL(triggered(bool)), recvr, slot); } } return pAction; } const char *name(StandardAction id) { const KStandardActionInfo *pInfo = infoPtr(id); - return (pInfo) ? pInfo->psName : 0; + return (pInfo) ? pInfo->psName : nullptr; } QAction *openNew(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(New, recvr, slot, parent); } QAction *open(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Open, recvr, slot, parent); } KRecentFilesAction *openRecent(const QObject *recvr, const char *slot, QObject *parent) { return (KRecentFilesAction *) KStandardAction::create(OpenRecent, recvr, slot, parent); } QAction *save(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Save, recvr, slot, parent); } QAction *saveAs(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(SaveAs, recvr, slot, parent); } QAction *revert(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Revert, recvr, slot, parent); } QAction *print(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Print, recvr, slot, parent); } QAction *printPreview(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(PrintPreview, recvr, slot, parent); } QAction *close(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Close, recvr, slot, parent); } QAction *mail(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Mail, recvr, slot, parent); } QAction *quit(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Quit, recvr, slot, parent); } QAction *undo(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Undo, recvr, slot, parent); } QAction *redo(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Redo, recvr, slot, parent); } QAction *cut(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Cut, recvr, slot, parent); } QAction *copy(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Copy, recvr, slot, parent); } QAction *paste(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Paste, recvr, slot, parent); } QAction *pasteText(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(PasteText, recvr, slot, parent); } QAction *clear(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Clear, recvr, slot, parent); } QAction *selectAll(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(SelectAll, recvr, slot, parent); } QAction *deselect(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Deselect, recvr, slot, parent); } QAction *find(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Find, recvr, slot, parent); } QAction *findNext(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(FindNext, recvr, slot, parent); } QAction *findPrev(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(FindPrev, recvr, slot, parent); } QAction *replace(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Replace, recvr, slot, parent); } QAction *actualSize(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(ActualSize, recvr, slot, parent); } QAction *fitToPage(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(FitToPage, recvr, slot, parent); } QAction *fitToWidth(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(FitToWidth, recvr, slot, parent); } QAction *fitToHeight(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(FitToHeight, recvr, slot, parent); } QAction *zoomIn(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(ZoomIn, recvr, slot, parent); } QAction *zoomOut(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(ZoomOut, recvr, slot, parent); } QAction *zoom(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Zoom, recvr, slot, parent); } QAction *redisplay(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Redisplay, recvr, slot, parent); } QAction *up(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Up, recvr, slot, parent); } QAction *back(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Back, recvr, slot, parent); } QAction *forward(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Forward, recvr, slot, parent); } QAction *home(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Home, recvr, slot, parent); } QAction *prior(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Prior, recvr, slot, parent); } QAction *next(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Next, recvr, slot, parent); } QAction *goTo(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Goto, recvr, slot, parent); } QAction *gotoPage(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(GotoPage, recvr, slot, parent); } QAction *gotoLine(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(GotoLine, recvr, slot, parent); } QAction *firstPage(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(FirstPage, recvr, slot, parent); } QAction *lastPage(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(LastPage, recvr, slot, parent); } QAction *documentBack(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(DocumentBack, recvr, slot, parent); } QAction *documentForward(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(DocumentForward, recvr, slot, parent); } QAction *addBookmark(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(AddBookmark, recvr, slot, parent); } QAction *editBookmarks(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(EditBookmarks, recvr, slot, parent); } QAction *spelling(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Spelling, recvr, slot, parent); } static QAction *buildAutomaticAction(QObject *parent, StandardAction id, const char *slot) { const KStandardActionInfo *p = infoPtr(id); if (!p) { - return 0; + return nullptr; } AutomaticAction *action = new AutomaticAction( QIcon::fromTheme(p->psIconName), i18n(p->psLabel), KStandardShortcut::shortcut(p->idAccel), slot, parent); action->setObjectName(p->psName); if (p->psToolTip) { action->setToolTip(i18n(p->psToolTip)); } if (parent && parent->inherits("KActionCollection")) { QMetaObject::invokeMethod(parent, "addAction", Q_ARG(QString, action->objectName()), Q_ARG(QAction *, action)); } return action; } QAction *cut(QObject *parent) { return buildAutomaticAction(parent, Cut, SLOT(cut())); } QAction *copy(QObject *parent) { return buildAutomaticAction(parent, Copy, SLOT(copy())); } QAction *paste(QObject *parent) { return buildAutomaticAction(parent, Paste, SLOT(paste())); } QAction *clear(QObject *parent) { return buildAutomaticAction(parent, Clear, SLOT(clear())); } QAction *selectAll(QObject *parent) { return buildAutomaticAction(parent, SelectAll, SLOT(selectAll())); } KToggleAction *showMenubar(const QObject *recvr, const char *slot, QObject *parent) { QAction* ret = KStandardAction::create(ShowMenubar, recvr, slot, parent); Q_ASSERT(qobject_cast(ret)); return static_cast(ret); } KToggleAction *showStatusbar(const QObject *recvr, const char *slot, QObject *parent) { QAction* ret = KStandardAction::create(ShowStatusbar, recvr, slot, parent); Q_ASSERT(qobject_cast(ret)); return static_cast(ret); } KToggleFullScreenAction *fullScreen(const QObject *recvr, const char *slot, QWidget *window, QObject *parent) { KToggleFullScreenAction *ret; ret = static_cast< KToggleFullScreenAction * >(KStandardAction::create(FullScreen, recvr, slot, parent)); ret->setWindow(window); return ret; } QAction *saveOptions(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(SaveOptions, recvr, slot, parent); } QAction *keyBindings(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(KeyBindings, recvr, slot, parent); } QAction *preferences(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Preferences, recvr, slot, parent); } QAction *configureToolbars(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(ConfigureToolbars, recvr, slot, parent); } QAction *configureNotifications(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(ConfigureNotifications, recvr, slot, parent); } QAction *help(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Help, recvr, slot, parent); } QAction *helpContents(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(HelpContents, recvr, slot, parent); } QAction *whatsThis(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(WhatsThis, recvr, slot, parent); } QAction *tipOfDay(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(TipofDay, recvr, slot, parent); } QAction *reportBug(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(ReportBug, recvr, slot, parent); } QAction *switchApplicationLanguage(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(SwitchApplicationLanguage, recvr, slot, parent); } QAction *aboutApp(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(AboutApp, recvr, slot, parent); } QAction *aboutKDE(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(AboutKDE, recvr, slot, parent); } QAction *deleteFile(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(DeleteFile, recvr, slot, parent); } QAction *renameFile(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(RenameFile, recvr, slot, parent); } QAction *moveToTrash(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(MoveToTrash, recvr, slot, parent); } QAction *donate(const QObject *recvr, const char *slot, QObject *parent) { return KStandardAction::create(Donate, recvr, slot, parent); } } diff --git a/src/kstandardaction_p.h b/src/kstandardaction_p.h index 264f9b5..848d80e 100644 --- a/src/kstandardaction_p.h +++ b/src/kstandardaction_p.h @@ -1,192 +1,192 @@ /* This file is part of the KDE libraries Copyright (C) 1999,2000 Kurt Granroth This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KSTANDARDACTION_PRIVATE_H #define KSTANDARDACTION_PRIVATE_H #include #include #include #include namespace KStandardAction { struct KStandardActionInfo { StandardAction id; KStandardShortcut::StandardShortcut idAccel; const char *psName; const char *psLabel; const char *psToolTip; const char *psIconName; }; static const KStandardActionInfo g_rgActionInfo[] = { { New, KStandardShortcut::New, "file_new", I18N_NOOP("&New"), I18N_NOOP("Create new document"), "document-new" }, { Open, KStandardShortcut::Open, "file_open", I18N_NOOP("&Open..."), I18N_NOOP("Open an existing document"), "document-open" }, { OpenRecent, KStandardShortcut::AccelNone, "file_open_recent", I18N_NOOP("Open &Recent"), I18N_NOOP("Open a document which was recently opened"), "document-open-recent" }, { Save, KStandardShortcut::Save, "file_save", I18N_NOOP("&Save"), I18N_NOOP("Save document"), "document-save" }, { SaveAs, KStandardShortcut::SaveAs, "file_save_as", I18N_NOOP("Save &As..."), I18N_NOOP("Save document under a new name"), "document-save-as" }, { Revert, KStandardShortcut::Revert, "file_revert", I18N_NOOP("Re&vert"), I18N_NOOP("Revert unsaved changes made to document"), "document-revert" }, { Close, KStandardShortcut::Close, "file_close", I18N_NOOP("&Close"), I18N_NOOP("Close document"), "window-close" }, { Print, KStandardShortcut::Print, "file_print", I18N_NOOP("&Print..."), I18N_NOOP("Print document"), "document-print" }, { PrintPreview, KStandardShortcut::PrintPreview, "file_print_preview", I18N_NOOP("Print Previe&w"), I18N_NOOP("Show a print preview of document"), "document-print-preview" }, { Mail, KStandardShortcut::Mail, "file_mail", I18N_NOOP("&Mail..."), I18N_NOOP("Send document by mail"), "mail-send" }, { Quit, KStandardShortcut::Quit, "file_quit", I18N_NOOP("&Quit"), I18N_NOOP("Quit application"), "application-exit" }, { Undo, KStandardShortcut::Undo, "edit_undo", I18N_NOOP("&Undo"), I18N_NOOP("Undo last action"), "edit-undo" }, { Redo, KStandardShortcut::Redo, "edit_redo", I18N_NOOP("Re&do"), I18N_NOOP("Redo last undone action"), "edit-redo" }, { Cut, KStandardShortcut::Cut, "edit_cut", I18N_NOOP("Cu&t"), I18N_NOOP("Cut selection to clipboard"), "edit-cut" }, { Copy, KStandardShortcut::Copy, "edit_copy", I18N_NOOP("&Copy"), I18N_NOOP("Copy selection to clipboard"), "edit-copy" }, { Paste, KStandardShortcut::Paste, "edit_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste clipboard content"), "edit-paste" }, { PasteText, KStandardShortcut::Paste, "edit_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste clipboard content"), "edit-paste" }, - { Clear, KStandardShortcut::Clear, "edit_clear", I18N_NOOP("C&lear"), 0, "edit-clear" }, - { SelectAll, KStandardShortcut::SelectAll, "edit_select_all", I18N_NOOP("Select &All"), 0, "edit-select-all" }, - { Deselect, KStandardShortcut::Deselect, "edit_deselect", I18N_NOOP("Dese&lect"), 0, 0 }, - { Find, KStandardShortcut::Find, "edit_find", I18N_NOOP("&Find..."), 0, "edit-find" }, - { FindNext, KStandardShortcut::FindNext, "edit_find_next", I18N_NOOP("Find &Next"), 0, "go-down-search" }, - { FindPrev, KStandardShortcut::FindPrev, "edit_find_prev", I18N_NOOP("Find Pre&vious"), 0, "go-up-search" }, - { Replace, KStandardShortcut::Replace, "edit_replace", I18N_NOOP("&Replace..."), 0, 0 }, + { Clear, KStandardShortcut::Clear, "edit_clear", I18N_NOOP("C&lear"), nullptr, "edit-clear" }, + { SelectAll, KStandardShortcut::SelectAll, "edit_select_all", I18N_NOOP("Select &All"), nullptr, "edit-select-all" }, + { Deselect, KStandardShortcut::Deselect, "edit_deselect", I18N_NOOP("Dese&lect"), nullptr, nullptr }, + { Find, KStandardShortcut::Find, "edit_find", I18N_NOOP("&Find..."), nullptr, "edit-find" }, + { FindNext, KStandardShortcut::FindNext, "edit_find_next", I18N_NOOP("Find &Next"), nullptr, "go-down-search" }, + { FindPrev, KStandardShortcut::FindPrev, "edit_find_prev", I18N_NOOP("Find Pre&vious"), nullptr, "go-up-search" }, + { Replace, KStandardShortcut::Replace, "edit_replace", I18N_NOOP("&Replace..."), nullptr, nullptr }, { ActualSize, KStandardShortcut::ActualSize, "view_actual_size", I18N_NOOP("&Actual Size"), I18N_NOOP("View document at its actual size"), "zoom-original" }, - { FitToPage, KStandardShortcut::FitToPage, "view_fit_to_page", I18N_NOOP("&Fit to Page"), I18N_NOOP("Zoom to fit page in window"), 0 }, - { FitToWidth, KStandardShortcut::FitToWidth, "view_fit_to_width", I18N_NOOP("Fit to Page &Width"), I18N_NOOP("Zoom to fit page width in window"), 0 }, - { FitToHeight, KStandardShortcut::FitToHeight, "view_fit_to_height", I18N_NOOP("Fit to Page &Height"), I18N_NOOP("Zoom to fit page height in window"), 0 }, - { ZoomIn, KStandardShortcut::ZoomIn, "view_zoom_in", I18N_NOOP("Zoom &In"), 0, "zoom-in" }, - { ZoomOut, KStandardShortcut::ZoomOut, "view_zoom_out", I18N_NOOP("Zoom &Out"), 0, "zoom-out" }, - { Zoom, KStandardShortcut::Zoom, "view_zoom", I18N_NOOP("&Zoom..."), I18N_NOOP("Select zoom level"), 0 }, + { FitToPage, KStandardShortcut::FitToPage, "view_fit_to_page", I18N_NOOP("&Fit to Page"), I18N_NOOP("Zoom to fit page in window"), nullptr }, + { FitToWidth, KStandardShortcut::FitToWidth, "view_fit_to_width", I18N_NOOP("Fit to Page &Width"), I18N_NOOP("Zoom to fit page width in window"), nullptr }, + { FitToHeight, KStandardShortcut::FitToHeight, "view_fit_to_height", I18N_NOOP("Fit to Page &Height"), I18N_NOOP("Zoom to fit page height in window"), nullptr }, + { ZoomIn, KStandardShortcut::ZoomIn, "view_zoom_in", I18N_NOOP("Zoom &In"), nullptr, "zoom-in" }, + { ZoomOut, KStandardShortcut::ZoomOut, "view_zoom_out", I18N_NOOP("Zoom &Out"), nullptr, "zoom-out" }, + { Zoom, KStandardShortcut::Zoom, "view_zoom", I18N_NOOP("&Zoom..."), I18N_NOOP("Select zoom level"), nullptr }, { Redisplay, KStandardShortcut::Reload, "view_redisplay", I18N_NOOP("&Redisplay"), I18N_NOOP("Redisplay document"), "view-refresh" }, { Up, KStandardShortcut::Up, "go_up", I18N_NOOP("&Up"), I18N_NOOP("Go up"), "go-up" }, // The following three have special i18n() needs for sLabel - { Back, KStandardShortcut::Back, "go_back", 0, 0, "go-previous" }, - { Forward, KStandardShortcut::Forward, "go_forward", 0, 0, "go-next" }, - { Home, KStandardShortcut::Home, "go_home", 0, 0, "go-home" }, + { Back, KStandardShortcut::Back, "go_back", nullptr, nullptr, "go-previous" }, + { Forward, KStandardShortcut::Forward, "go_forward", nullptr, nullptr, "go-next" }, + { Home, KStandardShortcut::Home, "go_home", nullptr, nullptr, "go-home" }, { Prior, KStandardShortcut::Prior, "go_previous", I18N_NOOP("&Previous Page"), I18N_NOOP("Go to previous page"), "go-previous-view-page" }, { Next, KStandardShortcut::Next, "go_next", I18N_NOOP("&Next Page"), I18N_NOOP("Go to next page"), "go-next-view-page" }, - { Goto, KStandardShortcut::Goto, "go_goto", I18N_NOOP("&Go To..."), 0, 0 }, - { GotoPage, KStandardShortcut::GotoPage, "go_goto_page", I18N_NOOP("&Go to Page..."), 0, "go-jump" }, - { GotoLine, KStandardShortcut::GotoLine, "go_goto_line", I18N_NOOP("&Go to Line..."), 0, 0 }, + { Goto, KStandardShortcut::Goto, "go_goto", I18N_NOOP("&Go To..."), nullptr, nullptr }, + { GotoPage, KStandardShortcut::GotoPage, "go_goto_page", I18N_NOOP("&Go to Page..."), nullptr, "go-jump" }, + { GotoLine, KStandardShortcut::GotoLine, "go_goto_line", I18N_NOOP("&Go to Line..."), nullptr, nullptr }, { FirstPage, KStandardShortcut::Begin, "go_first", I18N_NOOP("&First Page"), I18N_NOOP("Go to first page"), "go-first-view-page" }, { LastPage, KStandardShortcut::End, "go_last", I18N_NOOP("&Last Page"), I18N_NOOP("Go to last page"), "go-last-view-page" }, { DocumentBack, KStandardShortcut::DocumentBack, "go_document_back", I18N_NOOP("&Back"), I18N_NOOP("Go back in document"), "go-previous" }, { DocumentForward, KStandardShortcut::DocumentForward, "go_document_forward", I18N_NOOP("&Forward"), I18N_NOOP("Go forward in document"), "go-next" }, - { AddBookmark, KStandardShortcut::AddBookmark, "bookmark_add", I18N_NOOP("&Add Bookmark"), 0, "bookmark-new" }, - { EditBookmarks, KStandardShortcut::EditBookmarks, "bookmark_edit", I18N_NOOP("&Edit Bookmarks..."), 0, "bookmarks-organize" }, + { AddBookmark, KStandardShortcut::AddBookmark, "bookmark_add", I18N_NOOP("&Add Bookmark"), nullptr, "bookmark-new" }, + { EditBookmarks, KStandardShortcut::EditBookmarks, "bookmark_edit", I18N_NOOP("&Edit Bookmarks..."), nullptr, "bookmarks-organize" }, { Spelling, KStandardShortcut::Spelling, "tools_spelling", I18N_NOOP("&Spelling..."), I18N_NOOP("Check spelling in document"), "tools-check-spelling" }, { ShowMenubar, KStandardShortcut::ShowMenubar, "options_show_menubar", I18N_NOOP("Show &Menubar"), I18N_NOOP("Show or hide menubar"), "show-menu" }, - { ShowToolbar, KStandardShortcut::ShowToolbar, "options_show_toolbar", I18N_NOOP("Show &Toolbar"), I18N_NOOP("Show or hide toolbar"), 0 }, - { ShowStatusbar, KStandardShortcut::ShowStatusbar, "options_show_statusbar", I18N_NOOP("Show St&atusbar"), I18N_NOOP("Show or hide statusbar"), 0 }, - { FullScreen, KStandardShortcut::FullScreen, "fullscreen", I18N_NOOP("F&ull Screen Mode"), 0, "view-fullscreen" }, - { SaveOptions, KStandardShortcut::SaveOptions, "options_save_options", I18N_NOOP("&Save Settings"), 0, 0 }, - { KeyBindings, KStandardShortcut::KeyBindings, "options_configure_keybinding", I18N_NOOP("Configure S&hortcuts..."), 0, "configure-shortcuts" }, - { Preferences, KStandardShortcut::Preferences, "options_configure", I18N_NOOP("&Configure %1..."), 0, "configure" }, - { ConfigureToolbars, KStandardShortcut::ConfigureToolbars, "options_configure_toolbars", I18N_NOOP("Configure Tool&bars..."), 0, "configure-toolbars" }, - { ConfigureNotifications, KStandardShortcut::ConfigureNotifications, "options_configure_notifications", I18N_NOOP("Configure &Notifications..."), 0, "preferences-desktop-notification" }, + { ShowToolbar, KStandardShortcut::ShowToolbar, "options_show_toolbar", I18N_NOOP("Show &Toolbar"), I18N_NOOP("Show or hide toolbar"), nullptr }, + { ShowStatusbar, KStandardShortcut::ShowStatusbar, "options_show_statusbar", I18N_NOOP("Show St&atusbar"), I18N_NOOP("Show or hide statusbar"), nullptr }, + { FullScreen, KStandardShortcut::FullScreen, "fullscreen", I18N_NOOP("F&ull Screen Mode"), nullptr, "view-fullscreen" }, + { SaveOptions, KStandardShortcut::SaveOptions, "options_save_options", I18N_NOOP("&Save Settings"), nullptr, nullptr }, + { KeyBindings, KStandardShortcut::KeyBindings, "options_configure_keybinding", I18N_NOOP("Configure S&hortcuts..."), nullptr, "configure-shortcuts" }, + { Preferences, KStandardShortcut::Preferences, "options_configure", I18N_NOOP("&Configure %1..."), nullptr, "configure" }, + { ConfigureToolbars, KStandardShortcut::ConfigureToolbars, "options_configure_toolbars", I18N_NOOP("Configure Tool&bars..."), nullptr, "configure-toolbars" }, + { ConfigureNotifications, KStandardShortcut::ConfigureNotifications, "options_configure_notifications", I18N_NOOP("Configure &Notifications..."), nullptr, "preferences-desktop-notification" }, // the idea here is that Contents is used in menus, and Help in dialogs, so both share the same // shortcut - { Help, KStandardShortcut::Help, "help", 0, 0, "help-contents" }, - { HelpContents, KStandardShortcut::Help, "help_contents", I18N_NOOP("%1 &Handbook"), 0, "help-contents" }, - { WhatsThis, KStandardShortcut::WhatsThis, "help_whats_this", I18N_NOOP("What's &This?"), 0, "help-contextual" }, - { TipofDay, KStandardShortcut::TipofDay, "help_show_tip", I18N_NOOP("Tip of the &Day"), 0, "help-hint" }, - { ReportBug, KStandardShortcut::ReportBug, "help_report_bug", I18N_NOOP("&Report Bug..."), 0, "tools-report-bug" }, - { SwitchApplicationLanguage, KStandardShortcut::SwitchApplicationLanguage, "switch_application_language", I18N_NOOP("Switch Application &Language..."), 0, "preferences-desktop-locale" }, - { AboutApp, KStandardShortcut::AccelNone, "help_about_app", I18N_NOOP("&About %1"), 0, 0 }, - { AboutKDE, KStandardShortcut::AccelNone, "help_about_kde", I18N_NOOP("About &KDE"), 0, "kde" }, - { DeleteFile, KStandardShortcut::DeleteFile, "deletefile", I18N_NOOP("&Delete File"), 0, "edit-delete" }, - { RenameFile, KStandardShortcut::RenameFile, "renamefile", I18N_NOOP("&Rename File"), 0, "edit-rename" }, - { MoveToTrash, KStandardShortcut::MoveToTrash, "movetotrash", I18N_NOOP("&Move to Trash"), 0, "edit-delete" }, + { Help, KStandardShortcut::Help, "help", nullptr, nullptr, "help-contents" }, + { HelpContents, KStandardShortcut::Help, "help_contents", I18N_NOOP("%1 &Handbook"), nullptr, "help-contents" }, + { WhatsThis, KStandardShortcut::WhatsThis, "help_whats_this", I18N_NOOP("What's &This?"), nullptr, "help-contextual" }, + { TipofDay, KStandardShortcut::TipofDay, "help_show_tip", I18N_NOOP("Tip of the &Day"), nullptr, "help-hint" }, + { ReportBug, KStandardShortcut::ReportBug, "help_report_bug", I18N_NOOP("&Report Bug..."), nullptr, "tools-report-bug" }, + { SwitchApplicationLanguage, KStandardShortcut::SwitchApplicationLanguage, "switch_application_language", I18N_NOOP("Switch Application &Language..."), nullptr, "preferences-desktop-locale" }, + { AboutApp, KStandardShortcut::AccelNone, "help_about_app", I18N_NOOP("&About %1"), nullptr, nullptr }, + { AboutKDE, KStandardShortcut::AccelNone, "help_about_kde", I18N_NOOP("About &KDE"), nullptr, "kde" }, + { DeleteFile, KStandardShortcut::DeleteFile, "deletefile", I18N_NOOP("&Delete File"), nullptr, "edit-delete" }, + { RenameFile, KStandardShortcut::RenameFile, "renamefile", I18N_NOOP("&Rename File"), nullptr, "edit-rename" }, + { MoveToTrash, KStandardShortcut::MoveToTrash, "movetotrash", I18N_NOOP("&Move to Trash"), nullptr, "edit-delete" }, { Donate, KStandardShortcut::Donate, "help_donate", I18N_NOOP("&Donate"), Q_NULLPTR, Q_NULLPTR}, - { ActionNone, KStandardShortcut::AccelNone, 0, 0, 0, 0 } + { ActionNone, KStandardShortcut::AccelNone, nullptr, nullptr, nullptr, nullptr } }; inline const KStandardActionInfo *infoPtr(StandardAction id) { for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) { if (g_rgActionInfo[i].id == id) { return &g_rgActionInfo[i]; } } - return 0; + return nullptr; } static inline QStringList internal_stdNames() { QStringList result; for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) if (g_rgActionInfo[i].psLabel) { if (QByteArray(g_rgActionInfo[i].psLabel).contains("%1")) // Prevents i18n from complaining about unsubstituted placeholder. { result.append(i18n(g_rgActionInfo[i].psLabel, QString())); } else { result.append(i18n(g_rgActionInfo[i].psLabel)); } } return result; } class AutomaticAction : public QAction { Q_OBJECT public: AutomaticAction(const QIcon &icon, const QString &text, const QList &shortcut, const char *slot, QObject *parent); public Q_SLOTS: inline void cut() { invokeEditSlot("cut"); } inline void copy() { invokeEditSlot("copy"); } inline void paste() { invokeEditSlot("paste"); } inline void clear() { invokeEditSlot("clear"); } inline void selectAll() { invokeEditSlot("selectAll"); } void invokeEditSlot(const char *slot) { if (qApp->focusWidget()) { QMetaObject::invokeMethod(qApp->focusWidget(), slot); } } }; } #endif diff --git a/src/ktipdialog.cpp b/src/ktipdialog.cpp index 455f1d7..8922368 100644 --- a/src/ktipdialog.cpp +++ b/src/ktipdialog.cpp @@ -1,427 +1,427 @@ /***************************************************************** Copyright (c) 2000-2003 Matthias Hoelzer-Kluepfel Tobias Koenig Daniel Molkentin Copyright (c) 2008 Urs Wolfer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #include "ktipdialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class Q_DECL_HIDDEN KTipDatabase::Private { public: void loadTips(const QString &tipFile); void addTips(const QString &tipFile); QStringList tips; int currentTip; }; void KTipDatabase::Private::loadTips(const QString &tipFile) { tips.clear(); addTips(tipFile); } /** * If you change something here, please update the script * preparetips5, which depends on extracting exactly the same * text as done here. */ void KTipDatabase::Private::addTips(const QString &tipFile) { const QString fileName = QStandardPaths::locate(QStandardPaths::GenericDataLocation, tipFile); if (fileName.isEmpty()) { qDebug() << "KTipDatabase::addTips: can't find '" << tipFile << "' in standard dirs"; return; } QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { qDebug() << "KTipDatabase::addTips: can't open '" << fileName << "' for reading"; return; } QByteArray data = file.readAll(); QString content = QString::fromUtf8(data.constData(), data.size()); const QRegExp rx(QStringLiteral("\\n+")); int pos = -1; while ((pos = content.indexOf(QStringLiteral(""), pos + 1, Qt::CaseInsensitive)) != -1) { /** * To make translations work, tip extraction here must exactly * match what is done by the preparetips5 script. */ QString tip = content .mid(pos + 6, content.indexOf(QStringLiteral(""), pos, Qt::CaseInsensitive) - pos - 6) .replace(rx, QStringLiteral("\n")); if (!tip.endsWith('\n')) { tip += '\n'; } if (tip.startsWith('\n')) { tip = tip.mid(1); } if (tip.isEmpty()) { qDebug() << "Empty tip found! Skipping! " << pos; continue; } tips.append(tip); } file.close(); } KTipDatabase::KTipDatabase(const QString &_tipFile) : d(new Private) { QString tipFile = _tipFile; if (tipFile.isEmpty()) { tipFile = QCoreApplication::applicationName() + "/tips"; } d->loadTips(tipFile); if (!d->tips.isEmpty()) { d->currentTip = KRandom::random() % d->tips.count(); } } KTipDatabase::KTipDatabase(const QStringList &tipsFiles) : d(new Private) { if (tipsFiles.isEmpty() || ((tipsFiles.count() == 1) && tipsFiles.first().isEmpty())) { d->addTips(QCoreApplication::applicationName() + "/tips"); } else { for (QStringList::ConstIterator it = tipsFiles.begin(); it != tipsFiles.end(); ++it) { d->addTips(*it); } } if (!d->tips.isEmpty()) { d->currentTip = KRandom::random() % d->tips.count(); } } KTipDatabase::~KTipDatabase() { delete d; } void KTipDatabase::nextTip() { if (d->tips.isEmpty()) { return; } d->currentTip += 1; if (d->currentTip >= (int) d->tips.count()) { d->currentTip = 0; } } void KTipDatabase::prevTip() { if (d->tips.isEmpty()) { return; } d->currentTip -= 1; if (d->currentTip < 0) { d->currentTip = d->tips.count() - 1; } } QString KTipDatabase::tip() const { if (d->tips.isEmpty()) { return QString(); } return d->tips[ d->currentTip ]; } class Q_DECL_HIDDEN KTipDialog::Private { public: Private(KTipDialog *_parent) : parent(_parent) { } ~Private() { delete database; } void _k_nextTip(); void _k_prevTip(); void _k_showOnStart(bool); KTipDialog *parent; KTipDatabase *database; QCheckBox *tipOnStart; QTextBrowser *tipText; static KTipDialog *mInstance; }; -KTipDialog *KTipDialog::Private::mInstance = 0; +KTipDialog *KTipDialog::Private::mInstance = nullptr; void KTipDialog::Private::_k_prevTip() { database->prevTip(); tipText->setHtml(QStringLiteral("%1") .arg(i18nd(KLocalizedString::applicationDomain(), database->tip().toUtf8()))); } void KTipDialog::Private::_k_nextTip() { database->nextTip(); tipText->setHtml(QStringLiteral("%1") .arg(i18nd(KLocalizedString::applicationDomain(), database->tip().toUtf8()))); } void KTipDialog::Private::_k_showOnStart(bool on) { parent->setShowOnStart(on); } KTipDialog::KTipDialog(KTipDatabase *database, QWidget *parent) : QDialog(parent), d(new Private(this)) { setWindowTitle(i18nc("@title:window", "Tip of the Day")); /** * Parent is 0L when TipDialog is used as a mainWidget. This should * be the case only in ktip, so let's use the ktip layout. */ - bool isTipDialog = (parent != 0); + bool isTipDialog = (parent != nullptr); d->database = database; setWindowIcon(QIcon::fromTheme(QStringLiteral("ktip"))); QVBoxLayout *mainLayout = new QVBoxLayout(this); if (isTipDialog) { QLabel *titleLabel = new QLabel(this); titleLabel->setText(i18nc("@title", "Did you know...?\n")); titleLabel->setFont(QFont(qApp->font().family(), 20, QFont::Bold)); titleLabel->setAlignment(Qt::AlignCenter); mainLayout->addWidget(titleLabel); } QHBoxLayout *browserLayout = new QHBoxLayout(); mainLayout->addLayout(browserLayout); d->tipText = new QTextBrowser(this); d->tipText->setOpenExternalLinks(true); d->tipText->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); QStringList paths; paths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("icons"), QStandardPaths::LocateDirectory) << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("kdewizard/pics"), QStandardPaths::LocateDirectory); d->tipText->setSearchPaths(paths); d->tipText->setFrameStyle(QFrame::NoFrame); d->tipText->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QPalette tipPal(d->tipText->palette()); tipPal.setColor(QPalette::Base, Qt::transparent); tipPal.setColor(QPalette::Text, tipPal.color(QPalette::WindowText)); d->tipText->setPalette(tipPal); browserLayout->addWidget(d->tipText); QLabel *label = new QLabel(this); label->setPixmap(QStringLiteral(":/kconfigwidgets/pics/ktip-bulb.png")); label->setAlignment(Qt::AlignRight | Qt::AlignVCenter); browserLayout->addWidget(label); if (!isTipDialog) { resize(520, 280); QSize sh = size(); QRect rect = QApplication::desktop()->screenGeometry(QCursor::pos()); move(rect.x() + (rect.width() - sh.width()) / 2, rect.y() + (rect.height() - sh.height()) / 2); } KSeparator *sep = new KSeparator(Qt::Horizontal); mainLayout->addWidget(sep); QHBoxLayout *buttonLayout = new QHBoxLayout(); mainLayout->addLayout(buttonLayout); d->tipOnStart = new QCheckBox(i18nc("@option:check", "&Show tips on startup")); buttonLayout->addWidget(d->tipOnStart, 1); QPushButton *prev = new QPushButton; KGuiItem::assign(prev, KStandardGuiItem::back(KStandardGuiItem::UseRTL)); prev->setText(i18nc("@action:button Goes to previous tip", "&Previous")); buttonLayout->addWidget(prev); QPushButton *next = new QPushButton; KGuiItem::assign(next, KStandardGuiItem::forward(KStandardGuiItem::UseRTL)); next->setText(i18nc("@action:button Goes to next tip, opposite to previous", "&Next")); buttonLayout->addWidget(next); QPushButton *ok = new QPushButton; KGuiItem::assign(ok, KStandardGuiItem::close()); ok->setDefault(true); buttonLayout->addWidget(ok); KConfigGroup config(KSharedConfig::openConfig(), "TipOfDay"); d->tipOnStart->setChecked(config.readEntry("RunOnStart", true)); connect(next, SIGNAL(clicked()), this, SLOT(_k_nextTip())); connect(prev, SIGNAL(clicked()), this, SLOT(_k_prevTip())); connect(ok, SIGNAL(clicked()), this, SLOT(accept())); connect(d->tipOnStart, SIGNAL(toggled(bool)), this, SLOT(_k_showOnStart(bool))); ok->setFocus(); d->_k_nextTip(); } KTipDialog::~KTipDialog() { if (Private::mInstance == this) { - Private::mInstance = 0L; + Private::mInstance = nullptr; } delete d; } /** * use the one with a parent window as parameter instead of this one * or you will get focus problems */ void KTipDialog::showTip(const QString &tipFile, bool force) { - showTip(0, tipFile, force); + showTip(nullptr, tipFile, force); } void KTipDialog::showTip(QWidget *parent, const QString &tipFile, bool force) { showMultiTip(parent, QStringList(tipFile), force); } void KTipDialog::showMultiTip(QWidget *parent, const QStringList &tipFiles, bool force) { KConfigGroup configGroup(KSharedConfig::openConfig(), "TipOfDay"); const bool runOnStart = configGroup.readEntry("RunOnStart", true); if (!force) { if (!runOnStart) { return; } // showing the tooltips on startup suggests the tooltip // will be shown *each time* on startup, not $random days later // TODO either remove or uncomment this code, but make the situation clear /*bool hasLastShown = configGroup.hasKey( "TipLastShown" ); if ( hasLastShown ) { const int oneDay = 24 * 60 * 60; QDateTime lastShown = configGroup.readEntry( "TipLastShown", QDateTime() ); // Show tip roughly once a week if ( lastShown.secsTo( QDateTime::currentDateTime() ) < (oneDay + (KRandom::random() % (10 * oneDay))) ) return; } configGroup.writeEntry( "TipLastShown", QDateTime::currentDateTime() ); if ( !hasLastShown ) return; // Don't show tip on first start*/ } if (!Private::mInstance) { Private::mInstance = new KTipDialog(new KTipDatabase(tipFiles), parent); } else // The application might have changed the RunOnStart option in its own // configuration dialog, so we should update the checkbox. { Private::mInstance->d->tipOnStart->setChecked(runOnStart); } Private::mInstance->show(); Private::mInstance->raise(); } void KTipDialog::setShowOnStart(bool on) { KConfigGroup config(KSharedConfig::openConfig(), "TipOfDay"); config.writeEntry("RunOnStart", on); } bool KTipDialog::eventFilter(QObject *object, QEvent *event) { if (object == d->tipText && event->type() == QEvent::KeyPress && (((QKeyEvent *)event)->key() == Qt::Key_Return || ((QKeyEvent *)event)->key() == Qt::Key_Space)) { accept(); } /** * If the user presses Return or Space, we close the dialog as if the * default button was pressed even if the QTextBrowser has the keyboard * focus. This could have the bad side-effect that the user cannot use the * keyboard to open urls in the QTextBrowser, so we just let it handle * the key event _additionally_. (Antonio) */ return QWidget::eventFilter(object, event); } #include "moc_ktipdialog.cpp" diff --git a/src/ktipdialog.h b/src/ktipdialog.h index 67a7322..c6438c0 100644 --- a/src/ktipdialog.h +++ b/src/ktipdialog.h @@ -1,187 +1,187 @@ /***************************************************************** Copyright (c) 2000-2003 Matthias Hoelzer-Kluepfel Tobias Koenig Daniel Molkentin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #ifndef KTIP_H #define KTIP_H #include #include #include /** * A database for tips-of-the-day. * * This class provides convenient access to a database containing * tips of the day. The database is stored in a XML file and parsed * when a KTipDatabase object is created. * * Once the file is read in, you can access the tips to display * them in the tip of the day dialog. * * The state of the tipdialog is saved to the applications's config file * in the group "TipOfDay" with a bool entry "RunOnStart". Check this value * if you want to allow the user to enable/disable the tipdialog in the * application's configuration dialog. * * \image html ktip.png "KDE Tip-of-the-Day Dialog" * * @author Matthias Hoelzer-Kluepfel * */ class KCONFIGWIDGETS_EXPORT KTipDatabase { public: /** * This constructor reads in the tips from a file with the given name. If * no name is given, a file called 'application-name/tips' will be loaded. * * @param tipFile The absolute path to the tips file. */ explicit KTipDatabase(const QString &tipFile = QString()); /** * This constructor takes a list of files that will be merged. This constructor * essentially behaves like the one above. It returns when tipFiles is empty. * * @param tipFiles A list of absolute paths to the tips file */ explicit KTipDatabase(const QStringList &tipFiles); ~KTipDatabase(); /** * Returns the current tip. */ QString tip() const; /** * The next tip will become the current one. */ void nextTip(); /** * The previous tip will become the current one. */ void prevTip(); private: class Private; Private *const d; Q_DISABLE_COPY(KTipDatabase) }; /** * A Tip-of-the-Day dialog. * * This dialog class presents a tip-of-the-day. * * The tips will be looked up for translation using gettext * with KLocalizedString::applicationDomain() as domain. * * @author Matthias Hoelzer-Kluepfel */ class KCONFIGWIDGETS_EXPORT KTipDialog : public QDialog { Q_OBJECT public: /** * Construct a tip dialog. * * @param database TipDatabase that should be used by the TipDialog. The KTipDialog * will take ownership of the database, including deleting it. * @param parent Parent widget of TipDialog. */ - explicit KTipDialog(KTipDatabase *database, QWidget *parent = 0); + explicit KTipDialog(KTipDatabase *database, QWidget *parent = nullptr); /** * Destroys the tip dialog. */ ~KTipDialog(); /** * Shows a tip. * * This static method is all that is needed to add a tip-of-the-day * dialog to an application. It will pop up the dialog, unless the * user has asked that the dialog does not pop up on startup. * * Note that you probably want an item in the help menu calling * this method with force=true. * * @param parent Parent widget of TipDialog. * @param tipFile The name of the tip file. It has be relative to the GenericDataLocation * resource of QStandardPaths. * @param force If true, the dialog is show, even when the users * disabled it. */ static void showTip(QWidget *parent, const QString &tipFile = QString(), bool force = false); /** * Shows a tip * * This method behaves essentially as the one above, but expects a list of tips * * @param parent Parent widget of TipDialog. * @param tipFiles A List of tip files. Each has be relative to the GenericDataLocation * resource of QStandardPaths. * @param force If true, the dialog is show, even when the users * disabled it. */ static void showMultiTip(QWidget *parent, const QStringList &tipFiles, bool force = false); /** * Shows a tip. * * This methods calls showTip() with the applications main window as parent. * */ static void showTip(const QString &tipFile = QString(), bool force = false); /** * Toggles the start behavior. * * Normally, the user can disable the display of the tip in the dialog. * This is just a way to change this setting from outside. */ static void setShowOnStart(bool show); protected: bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; private: class Private; Private *const d; Q_PRIVATE_SLOT(d, void _k_nextTip()) Q_PRIVATE_SLOT(d, void _k_prevTip()) Q_PRIVATE_SLOT(d, void _k_showOnStart(bool)) Q_DISABLE_COPY(KTipDialog) }; #endif diff --git a/tests/kcodecactiontest.h b/tests/kcodecactiontest.h index c0546f7..285dc07 100644 --- a/tests/kcodecactiontest.h +++ b/tests/kcodecactiontest.h @@ -1,28 +1,28 @@ #ifndef KSELECTACTION_TEST_H #define KSELECTACTION_TEST_H #include class KCodecAction; class CodecActionTest : public QMainWindow { Q_OBJECT public: - CodecActionTest(QWidget *parent = 0); + CodecActionTest(QWidget *parent = nullptr); public Q_SLOTS: void triggered(QAction *action); void triggered(int index); void triggered(const QString &text); void triggered(QTextCodec *codec); void slotActionTriggered(bool state); private: KCodecAction *m_comboCodec; KCodecAction *m_buttonCodec; }; #endif diff --git a/tests/kcolorschemedemo.cpp b/tests/kcolorschemedemo.cpp index d92f681..f413f6d 100644 --- a/tests/kcolorschemedemo.cpp +++ b/tests/kcolorschemedemo.cpp @@ -1,66 +1,66 @@ /* This file is part of the KDE project * Copyright (C) 2013 Martin Gräßlin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include class KColorSchemeDemo : public QDialog { Q_OBJECT public: - KColorSchemeDemo() : QDialog(0) + KColorSchemeDemo() : QDialog(nullptr) { KColorSchemeManager *manager = new KColorSchemeManager(this); QListView *view = new QListView(this); view->setModel(manager->model()); connect(view, &QListView::activated, manager, &KColorSchemeManager::activateScheme); QDialogButtonBox *box = new QDialogButtonBox(QDialogButtonBox::Close, this); connect(box, &QDialogButtonBox::rejected, qApp, &QApplication::quit); QToolButton *button = new QToolButton(box); button->setIcon(QIcon::fromTheme(QStringLiteral("fill-color"))); button->setMenu(manager->createSchemeSelectionMenu(QStringLiteral("Oxygen"), button)->menu()); box->addButton(button, QDialogButtonBox::InvalidRole); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(view); layout->addWidget(box); setLayout(layout); } ~KColorSchemeDemo() {} }; int main(int argc, char *argv[]) { QApplication app(argc, argv); KColorSchemeDemo *d = new KColorSchemeDemo; d->show(); return app.exec(); } #include "kcolorschemedemo.moc" diff --git a/tests/kcolorutilsdemo.h b/tests/kcolorutilsdemo.h index 74e092f..052a9f6 100644 --- a/tests/kcolorutilsdemo.h +++ b/tests/kcolorutilsdemo.h @@ -1,47 +1,47 @@ /* * Copyright 2009 Matthew Woehlke * * 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 KCOLORUTILSDEMO_H #define KCOLORUTILSDEMO_H #include "ui_kcolorutilsdemo.h" class KColorUtilsDemo: public QWidget, Ui::form { Q_OBJECT public: - KColorUtilsDemo(QWidget *parent = 0); + KColorUtilsDemo(QWidget *parent = nullptr); virtual ~KColorUtilsDemo() {} public Q_SLOTS: void inputChanged(); void lumaChanged(); void mixChanged(); void shadeChanged(); void inputSpinChanged(); void inputSwatchChanged(const QColor &); void targetSpinChanged(); void targetSwatchChanged(const QColor &); protected: QImage _leOutImg, _mtMixOutImg, _mtTintOutImg; bool _noUpdate; }; #endif diff --git a/tests/kimageframe.h b/tests/kimageframe.h index 0d6a3a4..6f320a0 100644 --- a/tests/kimageframe.h +++ b/tests/kimageframe.h @@ -1,41 +1,41 @@ /* * Copyright 2009 Matthew Woehlke * * 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 KIMAGEFRAME_H #define KIMAGEFRAME_H #include class KImageFrame : public QFrame { Q_OBJECT public: - KImageFrame(QWidget *parent = 0); + KImageFrame(QWidget *parent = nullptr); virtual ~KImageFrame() {} public Q_SLOTS: void setImage(const QImage &); protected Q_SLOTS: void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; protected: QImage _img; int _w, _h; }; #endif