diff --git a/tools/onlinequoteseditor/CMakeLists.txt b/tools/onlinequoteseditor/CMakeLists.txt index c1d6c69..23b2da4 100644 --- a/tools/onlinequoteseditor/CMakeLists.txt +++ b/tools/onlinequoteseditor/CMakeLists.txt @@ -1,48 +1,50 @@ add_subdirectory(icons) include_directories( ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ) set(SOURCES + applicationsettings.cpp main.cpp mainwindow.cpp ) set(HEADERS + applicationsettings.h mainwindow.h ) set(UI mainwindow.ui ) ki18n_wrap_ui(SOURCES ${UI} ) ecm_add_app_icon(SOURCES ICONS icons/16-apps-onlinequoteseditor.png icons/22-apps-onlinequoteseditor.png icons/32-apps-onlinequoteseditor.png icons/48-apps-onlinequoteseditor.png icons/64-apps-onlinequoteseditor.png icons/128-apps-onlinequoteseditor.png ) ecm_add_executable(onlinequoteseditor ${SOURCES} ${HEADERS}) if(BUILD_QT4) set(LIBS ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}Network ${QT_USE_LIBSPREFIX}WebKit) else() set(LIBS Qt5::Widgets Qt5::WebKitWidgets KF5::KDELibs4Support) add_definitions(-DTRANSLATION_DOMAIN=\"onlinequoteseditor\") endif() target_link_libraries(onlinequoteseditor alkimia alkimia-internal ${LIBS} ) install(TARGETS onlinequoteseditor ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES org.kde.onlinequoteeditor.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) diff --git a/tools/onlinequoteseditor/applicationsettings.cpp b/tools/onlinequoteseditor/applicationsettings.cpp new file mode 100644 index 0000000..acf2229 --- /dev/null +++ b/tools/onlinequoteseditor/applicationsettings.cpp @@ -0,0 +1,88 @@ +/*************************************************************************** + * Copyright 2019 Ralf Habacker * + * * + * This file is part of libalkimia. * + * * + * libalkimia 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.1 of * + * the License or (at your option) version 3 or any later version. * + * * + * libalkimia is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see * + ***************************************************************************/ + +#include "applicationsettings.h" + +#include +#include +#include + +ApplicationSettings::ApplicationSettings(QMainWindow *parent, bool loadSettings) + : m_parent(parent) +{ + if (loadSettings) + readPositionSettings(); +} + +void ApplicationSettings::writePositionSettings() +{ + QSettings settings; + + settings.beginGroup("mainwindow"); + + settings.setValue("geometry", m_parent->saveGeometry()); + settings.setValue("savestate", m_parent->saveState()); + settings.setValue("maximized", m_parent->isMaximized()); + if (!m_parent->isMaximized()) { + settings.setValue("pos", m_parent->pos()); + settings.setValue("size", m_parent->size()); + } + settings.endGroup(); + + QList dockWidgets = m_parent->findChildren(); + foreach(QDockWidget *widget, dockWidgets) + { + settings.beginGroup(widget->objectName()); + settings.setValue("geometry", widget->saveGeometry()); + settings.setValue("maximized", widget->isMaximized()); + if (!widget->isMaximized()) { + settings.setValue("pos", widget->pos()); + settings.setValue("size", widget->size()); + } + settings.endGroup(); + } +} + +void ApplicationSettings::readPositionSettings() +{ + QSettings settings; + + settings.beginGroup("mainwindow"); + + m_parent->restoreGeometry(settings.value("geometry", m_parent->saveGeometry()).toByteArray()); + m_parent->restoreState(settings.value("savestate", m_parent->saveState()).toByteArray()); + m_parent->move(settings.value("pos", m_parent->pos()).toPoint()); + m_parent->resize(settings.value("size", m_parent->size()).toSize()); + if (settings.value("maximized", m_parent->isMaximized()).toBool()) + m_parent->showMaximized(); + + settings.endGroup(); + + QList dockWidgets = m_parent->findChildren(); + foreach(QDockWidget *widget, dockWidgets) + { + settings.beginGroup(widget->objectName()); + widget->restoreGeometry(settings.value("geometry", widget->saveGeometry()).toByteArray()); + widget->move(settings.value("pos", widget->pos()).toPoint()); + widget->resize(settings.value("size", widget->size()).toSize()); + if (settings.value("maximized", widget->isMaximized()).toBool()) + widget->showMaximized(); + settings.endGroup(); + } +} diff --git a/tools/onlinequoteseditor/mainwindow.h b/tools/onlinequoteseditor/applicationsettings.h similarity index 73% copy from tools/onlinequoteseditor/mainwindow.h copy to tools/onlinequoteseditor/applicationsettings.h index 85ce903..a619bcc 100644 --- a/tools/onlinequoteseditor/mainwindow.h +++ b/tools/onlinequoteseditor/applicationsettings.h @@ -1,45 +1,34 @@ /*************************************************************************** - * Copyright 2018 Ralf Habacker * + * Copyright 2019 Ralf Habacker * * * * This file is part of libalkimia. * * * * libalkimia 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.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia 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 MAINWINDOW_H -#define MAINWINDOW_H +#ifndef APPLICATIONSETTINGS_H +#define APPLICATIONSETTINGS_H -#include +class QMainWindow; -class QUrl; - -class MainWindow : public QMainWindow +class ApplicationSettings { - Q_OBJECT - -public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); - -protected slots: - void slotUrlChanged(const QUrl &url); - void slotEditingFinished(); - void slotLanguageChanged(const QString &); - -private: - class Private; - Private *const d; +protected: + ApplicationSettings(QMainWindow *parent, bool loadSettings = true); + void writePositionSettings(); + void readPositionSettings(); + QMainWindow *m_parent; }; -#endif // MAINWINDOW_H +#endif // APPLICATIONSETTINGS_H diff --git a/tools/onlinequoteseditor/mainwindow.cpp b/tools/onlinequoteseditor/mainwindow.cpp index 05320b5..7571531 100644 --- a/tools/onlinequoteseditor/mainwindow.cpp +++ b/tools/onlinequoteseditor/mainwindow.cpp @@ -1,150 +1,164 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * * * * This file is part of libalkimia. * * * * libalkimia 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.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see * ***************************************************************************/ #include "mainwindow.h" #include "ui_mainwindow.h" #include "alkonlinequotesprofile.h" #include "alkonlinequotesprofilemanager.h" #include "alkonlinequoteswidget.h" #include "alkwebpage.h" #include #include #include #include #include class MainWindow::Private { public: Private() : urlLine(nullptr) , quotesWidget(nullptr) { } ~Private() { delete quotesWidget; } QLineEdit *urlLine; AlkOnlineQuotesWidget *quotesWidget; Ui::MainWindow ui; }; void MainWindow::slotUrlChanged(const QUrl &url) { d->urlLine->setText(url.toString()); } void MainWindow::slotEditingFinished() { AlkOnlineQuotesProfileManager::instance().webPage()->load(QUrl(d->urlLine->text()), d->quotesWidget->acceptLanguage()); } void MainWindow::slotLanguageChanged(const QString &text) { d->quotesWidget->setAcceptLanguage(text); if (!d->urlLine->text().isEmpty()) slotEditingFinished(); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) + , ApplicationSettings(this, false) , d(new Private) { AlkOnlineQuotesProfileManager &manager = AlkOnlineQuotesProfileManager::instance(); manager.setWebPageEnabled(true); manager.addProfile(new AlkOnlineQuotesProfile("no-config-file", AlkOnlineQuotesProfile::Type::None)); manager.addProfile(new AlkOnlineQuotesProfile("alkimia4", AlkOnlineQuotesProfile::Type::Alkimia4, "alkimia-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("alkimia5", AlkOnlineQuotesProfile::Type::Alkimia5, "alkimia-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("skrooge4", AlkOnlineQuotesProfile::Type::Skrooge4, "skrooge-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("skrooge5", AlkOnlineQuotesProfile::Type::Skrooge5, "skrooge-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("kmymoney4", AlkOnlineQuotesProfile::Type::KMyMoney4, "kmymoney-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("kmymoney5", AlkOnlineQuotesProfile::Type::KMyMoney5, "kmymoney-quotes.knsrc")); d->ui.setupUi(this); d->quotesWidget = new AlkOnlineQuotesWidget(true, true); QDockWidget *profilesWidget = new QDockWidget(tr("Profiles"), this); + profilesWidget->setObjectName("profilesDockWidget"); profilesWidget->setWidget(d->quotesWidget->profilesWidget()); addDockWidget(Qt::LeftDockWidgetArea, profilesWidget); QDockWidget *profileDetailsWidget = new QDockWidget(tr("Profile details"), this); + profileDetailsWidget->setObjectName("profileDetailsDockWidget"); profileDetailsWidget->setWidget(d->quotesWidget->profileDetailsWidget()); addDockWidget(Qt::RightDockWidgetArea, profileDetailsWidget); QDockWidget *onlineQuotesWidget = new QDockWidget(tr("Online quotes"), this); + onlineQuotesWidget->setObjectName("onlineQuotesDockWidget"); onlineQuotesWidget->setWidget(d->quotesWidget->onlineQuotesWidget()); addDockWidget(Qt::LeftDockWidgetArea, onlineQuotesWidget); QDockWidget *debugWidget = new QDockWidget(tr("Debug"), this); + debugWidget->setObjectName("debugDockWidget"); debugWidget->setWidget(d->quotesWidget->debugWidget()); addDockWidget(Qt::LeftDockWidgetArea, debugWidget); QDockWidget *quoteDetailsWidget = new QDockWidget(tr("Quote details"), this); + quoteDetailsWidget->setObjectName("quoteDetailsDockWidget"); quoteDetailsWidget->setWidget(d->quotesWidget->quoteDetailsWidget()); addDockWidget(Qt::RightDockWidgetArea, quoteDetailsWidget); QDockWidget *browserWidget = new QDockWidget(tr("Browser"), this); + browserWidget->setObjectName("browserDockWidget"); AlkWebPage *webPage = manager.webPage(); connect(webPage, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl))); d->urlLine = new QLineEdit; connect(d->urlLine, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); // setup language box QComboBox *box = new QComboBox; QList allLocales = QLocale::matchingLocales( QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); QStringList languages; foreach(const QLocale &locale, allLocales) { languages.append(locale.uiLanguages()); } languages.sort(); box->addItems(languages); d->quotesWidget->setAcceptLanguage(box->currentText()); connect(box, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotLanguageChanged(QString))); // setup layouts QHBoxLayout *hLayout = new QHBoxLayout; hLayout->addWidget(d->urlLine); hLayout->addWidget(box); QVBoxLayout *layout = new QVBoxLayout; layout->addLayout(hLayout); layout->addWidget(webPage); QWidget *group = new QWidget; group->setLayout(layout); browserWidget->setWidget(group); addDockWidget(Qt::RightDockWidgetArea, browserWidget); setCentralWidget(nullptr); webPage->setWebInspectorEnabled(true); + readPositionSettings(); } MainWindow::~MainWindow() { delete d; } + +void MainWindow::closeEvent(QCloseEvent *event) +{ + writePositionSettings(); + QMainWindow::closeEvent(event); +} diff --git a/tools/onlinequoteseditor/mainwindow.h b/tools/onlinequoteseditor/mainwindow.h index 85ce903..54a660c 100644 --- a/tools/onlinequoteseditor/mainwindow.h +++ b/tools/onlinequoteseditor/mainwindow.h @@ -1,45 +1,49 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * * * * This file is part of libalkimia. * * * * libalkimia 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.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia 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 MAINWINDOW_H #define MAINWINDOW_H #include +#include "applicationsettings.h" class QUrl; -class MainWindow : public QMainWindow +class MainWindow : public QMainWindow, public ApplicationSettings { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); protected slots: void slotUrlChanged(const QUrl &url); void slotEditingFinished(); void slotLanguageChanged(const QString &); +protected: + void closeEvent(QCloseEvent *event) override; + private: class Private; Private *const d; }; #endif // MAINWINDOW_H