Git commit d2257c24d4249ec0e130a70b805192dfade2bf33 by Alexander Semke. Committed on 17/09/2016 at 08:12. Pushed by asemke into branch 'frameworks'.
Merge branch 'master' into frameworks M +1 -1 CMakeLists.txt M +17 -4 doc/index.docbook M +6 -1 src/CMakeLists.txt M +14 -0 src/backend/worksheet/TextLabel.cpp M +92 -4 src/backend/worksheet/plots/cartesian/Axis.cpp M +73 -10 src/backend/worksheet/plots/cartesian/CartesianPlot.cpp M +177 -0 src/backend/worksheet/plots/cartesian/XYCurve.cpp M +24 -3 src/commonfrontend/worksheet/WorksheetView.cpp M +6 -0 src/commonfrontend/worksheet/WorksheetView.h M +1 -1 src/kdefrontend/GuiObserver.cpp M +4 -4 src/kdefrontend/TemplateHandler.cpp M +9 -13 src/kdefrontend/TemplateHandler.h M +208 -0 src/kdefrontend/ThemeHandler.cpp M +25 -5 src/kdefrontend/dockwidgets/CartesianPlotDock.cpp M +6 -1 src/kdefrontend/dockwidgets/CartesianPlotDock.h M +1 -0 src/kdefrontend/dockwidgets/MatrixDock.cpp M +1 -0 src/kdefrontend/dockwidgets/SpreadsheetDock.cpp M +1 -0 src/kdefrontend/dockwidgets/WorksheetDock.cpp M +14 -3 src/kdefrontend/dockwidgets/XYDataReductionCurveDock.cpp M +104 -0 src/kdefrontend/widgets/ThemesWidget.cpp http://commits.kde.org/labplot/d2257c24d4249ec0e130a70b805192dfade2bf33 diff --cc CMakeLists.txt index b3adcd0,4addc82..e7c6cb6 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@@ -4,14 -4,12 +4,14 @@@ cmake_minimum_required(VERSION 2.8.12 find_package(ECM 1.3.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) -find_package(Qt4 REQUIRED) -find_package(KDE4 REQUIRED) +find_package(Qt5 ${QT_MIN_VERSION} REQUIRED NO_MODULE COMPONENTS Widgets Svg Concurrent) - find_package(KF5 REQUIRED COMPONENTS I18n KDELibs4Support) ++find_package(KF5 REQUIRED COMPONENTS I18n KDELibs4Support NewStuff) +include(FeatureSummary) include(ECMInstallIcons) include(KDEInstallDirs) -include(KDE4Defaults) +include(KDECompilerSettings) +include(KDECMakeSettings) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -Wunused -fno-omit-frame-pointer -fstack-protector -fno-exceptions") diff --cc src/CMakeLists.txt index fda1c24,822f638..74b81ea --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@@ -256,9 -246,9 +260,9 @@@ add_subdirectory( themes # set(LABPLOT_SRCS ${GUI_SOURCES} ${PLOTS_SOURCES} parser/parser.tab.c) set(LABPLOT_SRCS ${GUI_SOURCES} ${PLOTS_SOURCES}) INCLUDE_DIRECTORIES(. ${GSL_INCLUDE_DIR} ${GSL_INCLUDEDIR}/..) -kde4_add_ui_files(LABPLOT_SRCS ${UI_SOURCES}) -kde4_add_executable(labplot2 ${LABPLOT_SRCS} ${BACKEND_SOURCES} ${DATASOURCES_SOURCES} ${COMMONFRONTEND_SOURCES} ${TOOLS_SOURCES}) -target_link_libraries(labplot2 ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${KDE4_KNEWSTUFF3_LIBS} ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES} ${NETCDF_LIBRARY} ${FFTW_LIBRARIES} ${CFITSIO_LIBRARY}) +qt5_wrap_ui(LABPLOT_SRCS ${UI_SOURCES}) +add_executable(labplot2 ${LABPLOT_SRCS} ${BACKEND_SOURCES} ${CANTOR_SOURCES} ${DATASOURCES_SOURCES} ${COMMONFRONTEND_SOURCES} ${TOOLS_SOURCES} ${QTMOC_HDRS}) - target_link_libraries(labplot2 KF5::KDELibs4Support KF5::Archive KF5::XmlGui Qt5::Svg ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES} ${CANTOR_LIBS} ${NETCDF_LIBRARY} ${FFTW_LIBRARIES} ${CFITSIO_LIBRARY}) ++target_link_libraries(labplot2 KF5::KDELibs4Support KF5::Archive KF5::XmlGui KF5::NewStuff Qt5::Svg ${GSL_LIBRARIES} ${GSL_CBLAS_LIBRARIES} ${CANTOR_LIBS} ${NETCDF_LIBRARY} ${FFTW_LIBRARIES} ${CFITSIO_LIBRARY}) IF (HDF5_FOUND) target_link_libraries(labplot2 ${HDF5_C_LIBRARIES}) ENDIF (HDF5_FOUND) @@@ -266,9 -256,9 +270,10 @@@ ############## installation ################################ -install(TARGETS labplot2 DESTINATION ${BIN_INSTALL_DIR}) -install(FILES ${KDEFRONTEND_DIR}/labplot2ui.rc ${KDEFRONTEND_DIR}/splash.png DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}) +install(TARGETS labplot2 DESTINATION ${INSTALL_TARGETS_DEFAULT_ARGS}) +install(FILES ${KDEFRONTEND_DIR}/labplot2ui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/${PROJECT_NAME}) +install(FILES ${KDEFRONTEND_DIR}/labplot2ui.rc ${KDEFRONTEND_DIR}/splash.png ${KDEFRONTEND_DIR}/labplot2.ico DESTINATION ${DATA_INSTALL_DIR}/${PROJECT_NAME}) install(PROGRAMS labplot2.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) install( FILES labplot2.xml DESTINATION ${XDG_MIME_INSTALL_DIR} ) + install( FILES labplot2_themes.knsrc DESTINATION ${KDE_INSTALL_CONFDIR} ) update_xdg_mimetypes( ${XDG_MIME_INSTALL_DIR} ) diff --cc src/backend/worksheet/plots/cartesian/CartesianPlot.cpp index a5ee37f,8734365..755ff5d --- a/src/backend/worksheet/plots/cartesian/CartesianPlot.cpp +++ b/src/backend/worksheet/plots/cartesian/CartesianPlot.cpp @@@ -53,14 -53,13 +53,14 @@@ #include <QMenu> #include <QToolBar> #include <QPainter> - +#include <QIcon> +#include <QAction> - #include <KLocale> - - #define SCALE_MIN CartesianScale::LIMIT_MIN - #define SCALE_MAX CartesianScale::LIMIT_MAX ++#include <QWidgetAction> + #include <KConfigGroup> -#include <KIcon> -#include <KAction> + #include <KLocale> + #include "kdefrontend/ThemeHandler.h" + #include "kdefrontend/widgets/ThemesWidget.h" /** * \class CartesianPlot diff --cc src/commonfrontend/worksheet/WorksheetView.cpp index 4df36b0,5827fc0..8c2f8d5 --- a/src/commonfrontend/worksheet/WorksheetView.cpp +++ b/src/commonfrontend/worksheet/WorksheetView.cpp @@@ -272,64 -272,70 +272,70 @@@ void WorksheetView::initActions() connect(cartesianPlotMouseModeActionGroup, SIGNAL(triggered(QAction*)), SLOT(cartesianPlotMouseModeChanged(QAction*))); QActionGroup* cartesianPlotAddNewActionGroup = new QActionGroup(this); - addCurveAction = new KAction(KIcon("labplot-xy-curve"), i18n("xy-curve"), cartesianPlotAddNewActionGroup); - addEquationCurveAction = new KAction(KIcon("labplot-xy-equation-curve"), i18n("xy-curve from a mathematical equation"), cartesianPlotAddNewActionGroup); - addDataOperationCurveAction = new KAction(i18n("xy-curve from a data operation"), cartesianPlotAddNewActionGroup); - addDataReductionCurveAction = new KAction(i18n("xy-curve from a data reduction"), cartesianPlotAddNewActionGroup); - addDifferentationCurveAction = new KAction(i18n("xy-curve from a differentiation"), cartesianPlotAddNewActionGroup); - addIntegrationCurveAction = new KAction(i18n("xy-curve from an integration"), cartesianPlotAddNewActionGroup); + addCurveAction = new QAction(QIcon::fromTheme("labplot-xy-curve"), i18n("xy-curve"), cartesianPlotAddNewActionGroup); + addEquationCurveAction = new QAction(QIcon::fromTheme("labplot-xy-equation-curve"), i18n("xy-curve from a mathematical equation"), cartesianPlotAddNewActionGroup); - // no icons yet ++ addDataOperationCurveAction = new QAction(i18n("xy-curve from a data operation"), cartesianPlotAddNewActionGroup); + addDataReductionCurveAction = new QAction(i18n("xy-curve from a data reduction"), cartesianPlotAddNewActionGroup); ++ addDifferentationCurveAction = new QAction(i18n("xy-curve from a differentiation"), cartesianPlotAddNewActionGroup); ++ addIntegrationCurveAction = new QAction(i18n("xy-curve from an integration"), cartesianPlotAddNewActionGroup); + // no icons yet - addInterpolationCurveAction = new KAction(i18n("xy-curve from an interpolation"), cartesianPlotAddNewActionGroup); - addSmoothCurveAction = new KAction(i18n("xy-curve from a smooth"), cartesianPlotAddNewActionGroup); - addFourierFilterCurveAction = new KAction(i18n("xy-curve from a Fourier filter"), cartesianPlotAddNewActionGroup); - addFourierTransformCurveAction = new KAction(i18n("xy-curve from a Fourier transform"), cartesianPlotAddNewActionGroup); -// addInterpolationCurveAction = new KAction(KIcon("labplot-xy-interpolation-curve"), i18n("xy-curve from an interpolation"), cartesianPlotAddNewActionGroup); -// addSmoothCurveAction = new KAction(KIcon("labplot-xy-smooth-curve"), i18n("xy-curve from a smooth"), cartesianPlotAddNewActionGroup); - addFitCurveAction = new KAction(KIcon("labplot-xy-fit-curve"), i18n("xy-curve from a fit to data"), cartesianPlotAddNewActionGroup); -// addFourierFilterCurveAction = new KAction(KIcon("labplot-xy-fourier_filter-curve"), i18n("xy-curve from a Fourier filter"), cartesianPlotAddNewActionGroup); -// addFourierTransformCurveAction = new KAction(KIcon("labplot-xy-fourier_transform-curve"), i18n("xy-curve from a Fourier transform"), cartesianPlotAddNewActionGroup); - addLegendAction = new KAction(KIcon("text-field"), i18n("legend"), cartesianPlotAddNewActionGroup); - addHorizontalAxisAction = new KAction(KIcon("labplot-axis-horizontal"), i18n("horizontal axis"), cartesianPlotAddNewActionGroup); - addVerticalAxisAction = new KAction(KIcon("labplot-axis-vertical"), i18n("vertical axis"), cartesianPlotAddNewActionGroup); - addCustomPointAction = new KAction(KIcon("draw-cross"), i18n("custom point"), cartesianPlotAddNewActionGroup); + addInterpolationCurveAction = new QAction(i18n("xy-curve from an interpolation"), cartesianPlotAddNewActionGroup); + addSmoothCurveAction = new QAction(i18n("xy-curve from a smooth"), cartesianPlotAddNewActionGroup); - addFitCurveAction = new QAction(QIcon::fromTheme("labplot-xy-fit-curve"), i18n("xy-curve from a fit to data"), cartesianPlotAddNewActionGroup); + addFourierFilterCurveAction = new QAction(i18n("xy-curve from a Fourier filter"), cartesianPlotAddNewActionGroup); + addFourierTransformCurveAction = new QAction(i18n("xy-curve from a Fourier transform"), cartesianPlotAddNewActionGroup); +// addInterpolationCurveAction = new QAction(QIcon::fromTheme("labplot-xy-interpolation-curve"), i18n("xy-curve from an interpolation"), cartesianPlotAddNewActionGroup); +// addSmoothCurveAction = new QAction(QIcon::fromTheme("labplot-xy-smooth-curve"), i18n("xy-curve from a smooth"), cartesianPlotAddNewActionGroup); ++ addFitCurveAction = new QAction(QIcon::fromTheme("labplot-xy-fit-curve"), i18n("xy-curve from a fit to data"), cartesianPlotAddNewActionGroup); +// addFourierFilterCurveAction = new QAction(QIcon::fromTheme("labplot-xy-fourier_filter-curve"), i18n("xy-curve from a Fourier filter"), cartesianPlotAddNewActionGroup); +// addFourierTransformCurveAction = new QAction(QIcon::fromTheme("labplot-xy-fourier_transform-curve"), i18n("xy-curve from a Fourier transform"), cartesianPlotAddNewActionGroup); + addLegendAction = new QAction(QIcon::fromTheme("text-field"), i18n("legend"), cartesianPlotAddNewActionGroup); + addHorizontalAxisAction = new QAction(QIcon::fromTheme("labplot-axis-horizontal"), i18n("horizontal axis"), cartesianPlotAddNewActionGroup); + addVerticalAxisAction = new QAction(QIcon::fromTheme("labplot-axis-vertical"), i18n("vertical axis"), cartesianPlotAddNewActionGroup); + addCustomPointAction = new QAction(QIcon::fromTheme("draw-cross"), i18n("custom point"), cartesianPlotAddNewActionGroup); connect(cartesianPlotAddNewActionGroup, SIGNAL(triggered(QAction*)), SLOT(cartesianPlotAddNew(QAction*))); // Analysis menu - // no icons yet - addDataOperationAction = new KAction(i18n("Data operation"), cartesianPlotAddNewActionGroup); - addDataReductionAction = new KAction(i18n("Data reduction"), cartesianPlotAddNewActionGroup); - addDifferentiationAction = new KAction(i18n("Differentiation"), cartesianPlotAddNewActionGroup); - addIntegrationAction = new KAction(i18n("Integration"), cartesianPlotAddNewActionGroup); ++ addDataOperationAction = new QAction(i18n("Data operation"), cartesianPlotAddNewActionGroup); + addDataReductionAction = new QAction(i18n("Data reduction"), cartesianPlotAddNewActionGroup); ++ addDifferentiationAction = new QAction(i18n("Differentiation"), cartesianPlotAddNewActionGroup); ++ addIntegrationAction = new QAction(i18n("Integration"), cartesianPlotAddNewActionGroup); + // no icons yet - addInterpolationAction = new KAction(i18n("Interpolation"), cartesianPlotAddNewActionGroup); - addSmoothAction = new KAction(i18n("Smooth"), cartesianPlotAddNewActionGroup); - addFitAction = new KAction(KIcon("labplot-xy-fit-curve"), i18n("Data fitting"), cartesianPlotAddNewActionGroup); - addFourierFilterAction = new KAction(i18n("Fourier filter"), cartesianPlotAddNewActionGroup); - addFourierTransformAction = new KAction(i18n("Fourier transform"), cartesianPlotAddNewActionGroup); -// addInterpolationAction = new KAction(KIcon("labplot-xy-interpolation-curve"), i18n("Interpolation"), cartesianPlotAddNewActionGroup); -// addSmoothAction = new KAction(KIcon("labplot-xy-smooth-curve"), i18n("Smooth"), cartesianPlotAddNewActionGroup); -// addFourierFilterAction = new KAction(KIcon("labplot-xy-fourier_filter-curve"), i18n("Fourier filter"), cartesianPlotAddNewActionGroup); -// addFourierTransformAction = new KAction(KIcon("labplot-xy-fourier_transform-curve"), i18n("Fourier transform"), cartesianPlotAddNewActionGroup); + addInterpolationAction = new QAction(i18n("Interpolation"), cartesianPlotAddNewActionGroup); + addSmoothAction = new QAction(i18n("Smooth"), cartesianPlotAddNewActionGroup); + addFitAction = new QAction(QIcon::fromTheme("labplot-xy-fit-curve"), i18n("Data fitting"), cartesianPlotAddNewActionGroup); + addFourierFilterAction = new QAction(i18n("Fourier filter"), cartesianPlotAddNewActionGroup); + addFourierTransformAction = new QAction(i18n("Fourier transform"), cartesianPlotAddNewActionGroup); +// addInterpolationAction = new QAction(QIcon::fromTheme("labplot-xy-interpolation-curve"), i18n("Interpolation"), cartesianPlotAddNewActionGroup); +// addSmoothAction = new QAction(QIcon::fromTheme("labplot-xy-smooth-curve"), i18n("Smooth"), cartesianPlotAddNewActionGroup); +// addFourierFilterAction = new QAction(QIcon::fromTheme("labplot-xy-fourier_filter-curve"), i18n("Fourier filter"), cartesianPlotAddNewActionGroup); +// addFourierTransformAction = new QAction(QIcon::fromTheme("labplot-xy-fourier_transform-curve"), i18n("Fourier transform"), cartesianPlotAddNewActionGroup); QActionGroup* cartesianPlotNavigationGroup = new QActionGroup(this); - scaleAutoAction = new KAction(KIcon("labplot-auto-scale-all"), i18n("auto scale"), cartesianPlotNavigationGroup); + scaleAutoAction = new QAction(QIcon::fromTheme("labplot-auto-scale-all"), i18n("auto scale"), cartesianPlotNavigationGroup); scaleAutoAction->setData(CartesianPlot::ScaleAuto); - scaleAutoXAction = new KAction(KIcon("labplot-auto-scale-x"), i18n("auto scale X"), cartesianPlotNavigationGroup); + scaleAutoXAction = new QAction(QIcon::fromTheme("labplot-auto-scale-x"), i18n("auto scale X"), cartesianPlotNavigationGroup); scaleAutoXAction->setData(CartesianPlot::ScaleAutoX); - scaleAutoYAction = new KAction(KIcon("labplot-auto-scale-y"), i18n("auto scale Y"), cartesianPlotNavigationGroup); + scaleAutoYAction = new QAction(QIcon::fromTheme("labplot-auto-scale-y"), i18n("auto scale Y"), cartesianPlotNavigationGroup); scaleAutoYAction->setData(CartesianPlot::ScaleAutoY); - zoomInAction = new KAction(KIcon("zoom-in"), i18n("zoom in"), cartesianPlotNavigationGroup); + zoomInAction = new QAction(QIcon::fromTheme("zoom-in"), i18n("zoom in"), cartesianPlotNavigationGroup); zoomInAction->setData(CartesianPlot::ZoomIn); - zoomOutAction = new KAction(KIcon("zoom-out"), i18n("zoom out"), cartesianPlotNavigationGroup); + zoomOutAction = new QAction(QIcon::fromTheme("zoom-out"), i18n("zoom out"), cartesianPlotNavigationGroup); zoomOutAction->setData(CartesianPlot::ZoomOut); - zoomInXAction = new KAction(KIcon("labplot-zoom-in-x"), i18n("zoom in X"), cartesianPlotNavigationGroup); + zoomInXAction = new QAction(QIcon::fromTheme("labplot-zoom-in-x"), i18n("zoom in X"), cartesianPlotNavigationGroup); zoomInXAction->setData(CartesianPlot::ZoomInX); - zoomOutXAction = new KAction(KIcon("labplot-zoom-out-x"), i18n("zoom out X"), cartesianPlotNavigationGroup); + zoomOutXAction = new QAction(QIcon::fromTheme("labplot-zoom-out-x"), i18n("zoom out X"), cartesianPlotNavigationGroup); zoomOutXAction->setData(CartesianPlot::ZoomOutX); - zoomInYAction = new KAction(KIcon("labplot-zoom-in-y"), i18n("zoom in Y"), cartesianPlotNavigationGroup); + zoomInYAction = new QAction(QIcon::fromTheme("labplot-zoom-in-y"), i18n("zoom in Y"), cartesianPlotNavigationGroup); zoomInYAction->setData(CartesianPlot::ZoomInY); - zoomOutYAction = new KAction(KIcon("labplot-zoom-out-y"), i18n("zoom out Y"), cartesianPlotNavigationGroup); + zoomOutYAction = new QAction(QIcon::fromTheme("labplot-zoom-out-y"), i18n("zoom out Y"), cartesianPlotNavigationGroup); zoomOutYAction->setData(CartesianPlot::ZoomOutY); - shiftLeftXAction = new KAction(KIcon("labplot-shift-left-x"), i18n("shift left X"), cartesianPlotNavigationGroup); + shiftLeftXAction = new QAction(QIcon::fromTheme("labplot-shift-left-x"), i18n("shift left X"), cartesianPlotNavigationGroup); shiftLeftXAction->setData(CartesianPlot::ShiftLeftX); - shiftRightXAction = new KAction(KIcon("labplot-shift-right-x"), i18n("shift right X"), cartesianPlotNavigationGroup); + shiftRightXAction = new QAction(QIcon::fromTheme("labplot-shift-right-x"), i18n("shift right X"), cartesianPlotNavigationGroup); shiftRightXAction->setData(CartesianPlot::ShiftRightX); - shiftUpYAction = new KAction(KIcon("labplot-shift-up-y"), i18n("shift up Y"), cartesianPlotNavigationGroup); + shiftUpYAction = new QAction(QIcon::fromTheme("labplot-shift-up-y"), i18n("shift up Y"), cartesianPlotNavigationGroup); shiftUpYAction->setData(CartesianPlot::ShiftUpY); - shiftDownYAction = new KAction(KIcon("labplot-shift-down-y"), i18n("shift down Y"), cartesianPlotNavigationGroup); + shiftDownYAction = new QAction(QIcon::fromTheme("labplot-shift-down-y"), i18n("shift down Y"), cartesianPlotNavigationGroup); shiftDownYAction->setData(CartesianPlot::ShiftDownY); connect(cartesianPlotNavigationGroup, SIGNAL(triggered(QAction*)), SLOT(cartesianPlotNavigationChanged(QAction*))); @@@ -450,7 -461,8 +459,8 @@@ void WorksheetView::initMenus() // Data manipulation menu m_dataManipulationMenu = new QMenu(i18n("Data Manipulation")); - m_dataManipulationMenu->setIcon(KIcon("zoom-draw")); + m_dataManipulationMenu->setIcon(QIcon::fromTheme("zoom-draw")); + m_dataManipulationMenu->addAction(addDataOperationAction); m_dataManipulationMenu->addAction(addDataReductionAction); } diff --cc src/kdefrontend/TemplateHandler.h index 382fce8,3992cf0..4ec8b2b --- a/src/kdefrontend/TemplateHandler.h +++ b/src/kdefrontend/TemplateHandler.h @@@ -30,13 -30,11 +30,12 @@@ #ifndef TEMPLATEHANDLER_H #define TEMPLATEHANDLER_H - #include <QtWidgets/QWidget> - class QHBoxLayout; + #include <QWidget> ++ class QToolButton; - class QSpacerItem; class KConfig; - class TemplateHandler : public QWidget{ + class TemplateHandler : public QWidget { Q_OBJECT public: diff --cc src/kdefrontend/ThemeHandler.cpp index 0000000,53af77b..3f12381 mode 000000,100755..100755 --- a/src/kdefrontend/ThemeHandler.cpp +++ b/src/kdefrontend/ThemeHandler.cpp @@@ -1,0 -1,207 +1,208 @@@ + /*************************************************************************** + File : ThemeHandler.cpp + Project : LabPlot + Description : Widget for handling saving and loading of themes + -------------------------------------------------------------------- + Copyright : (C) 2016 Prakriti Bhardwaj ([email protected]) + Copyright : (C) 2016 Alexander Semke ([email protected]) + + ***************************************************************************/ + + /*************************************************************************** + * * + * 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, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + ***************************************************************************/ + + #include "ThemeHandler.h" + #include "widgets/ThemesWidget.h" + + #include <QDir> + #include <QHBoxLayout> + #include <QPushButton> + #include <QLabel> + #include <QFileInfo> + #include <QWidgetAction> + ++#include <KGlobal> + #include <KLocale> + #include <KStandardDirs> + #include <KLineEdit> + #include <KMenu> + #include <KConfig> + #include <KConfigGroup> + + #include <KMessageBox> -#include <knewstuff3/uploaddialog.h> ++#include <KNS3/UploadDialog> + + #include <unistd.h> + + /*! + \class ThemeHandler + \brief Provides a widget with buttons for loading of themes. + + Emits \c loadConfig() signal that have to be connected + to the appropriate slots in the backend (plot widgets) + + \ingroup kdefrontend + */ + + ThemeHandler::ThemeHandler(QWidget* parent) : QWidget(parent) { + QHBoxLayout* horizontalLayout = new QHBoxLayout(this); + horizontalLayout->setSpacing(0); + + pbLoadTheme = new QPushButton(this); + horizontalLayout->addWidget(pbLoadTheme); + pbLoadTheme->setText("Apply theme"); + + pbSaveTheme = new QPushButton(this); + horizontalLayout->addWidget(pbSaveTheme); + pbSaveTheme->setText("Save theme"); + + pbPublishTheme = new QPushButton(this); + horizontalLayout->addWidget(pbPublishTheme); + pbPublishTheme->setText("Publish theme"); + pbPublishTheme->setEnabled(false); + + QSpacerItem* horizontalSpacer2 = new QSpacerItem(10, 20, QSizePolicy::Fixed, QSizePolicy::Minimum); + horizontalLayout->addItem(horizontalSpacer2); + + connect( pbLoadTheme, SIGNAL(clicked()), this, SLOT(showPanel())); + connect( pbSaveTheme, SIGNAL(clicked()), this, SLOT(saveMenu())); + connect( pbPublishTheme, SIGNAL(clicked()), this, SLOT(publishThemes())); + + //find all available themes files (system wide and user specific local files) + //the list m_themeList contains full pathes (path + file name) + m_themeList = KGlobal::dirs()->findAllResources("appdata", "themes/*"); + pbLoadTheme->setEnabled(!m_themeList.empty()); + } + + void ThemeHandler::loadSelected(QString name) { + QString themeFilePath; + foreach(QString filePath, m_themeList) { + if( filePath.indexOf(name)!=-1 ) { + themeFilePath = filePath; + break; + } + } + KConfig config(themeFilePath, KConfig::SimpleConfig); + emit (loadThemeRequested(config)); + + emit info( i18n("Theme \"%1\" was loaded.", name) ); + + //in case a local theme file was loaded (we have write access), allow to publish it + if (KGlobal::dirs()->checkAccess(themeFilePath, W_OK)) { + pbPublishTheme->setEnabled(true); + m_currentLocalTheme = themeFilePath.right(themeFilePath.length() - themeFilePath.lastIndexOf(QDir::separator()) - 1); + } else { + pbPublishTheme->setEnabled(false); + m_currentLocalTheme.clear(); + } + } + + QStringList ThemeHandler::themes() { + QStringList pathList = KGlobal::dirs()->findAllResources("data", "labplot2/themes/*"); + pathList.append(KGlobal::dirs()->findAllResources("appdata", "themes/*")); + QStringList themeList; + for(int i = 0; i < pathList.size(); ++i) { + QFileInfo fileinfo(pathList.at(i)); + themeList.append(fileinfo.fileName().split('.').at(0)); + } + return themeList; + } + + const QString ThemeHandler::themeFilePath(const QString& name) { + QStringList themes = KGlobal::dirs()->findAllResources("data", "labplot2/themes/*"); + themes.append(KGlobal::dirs()->findAllResources("appdata", "themes/*")); + for (int i=0; i<themes.size(); ++i) { + if ( themes.at(i).indexOf(name)!=-1 ) + return themes.at(i); + } + + return QString(); + } + + void ThemeHandler::showPanel() { + QMenu menu; + ThemesWidget themeWidget(&menu); + connect(&themeWidget, SIGNAL(themeSelected(QString)), this, SLOT(loadSelected(QString))); + connect(&themeWidget, SIGNAL(themeSelected(QString)), &menu, SLOT(close())); + connect(&themeWidget, SIGNAL(canceled()), &menu, SLOT(close())); + + QWidgetAction* widgetAction = new QWidgetAction(this); + widgetAction->setDefaultWidget(&themeWidget); + menu.addAction(widgetAction); + + QPoint pos(-menu.sizeHint().width()+pbLoadTheme->width(),-menu.sizeHint().height()); + menu.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + menu.exec(pbLoadTheme->mapToGlobal(pos)); + } + + void ThemeHandler::saveMenu() { + KMenu menu; + menu.addTitle(i18n("Save as")); + + // add editable action + QWidgetAction* widgetAction = new QWidgetAction(this); + QFrame* frame = new QFrame(this); + QHBoxLayout* layout = new QHBoxLayout(frame); + + QLabel* label = new QLabel(i18n("Enter name:"), frame); + layout->addWidget(label); + + KLineEdit* leFilename = new KLineEdit("", frame); + layout->addWidget(leFilename); + connect(leFilename, SIGNAL(returnPressed(QString)), this, SLOT(saveNewSelected(QString))); + connect(leFilename, SIGNAL(returnPressed(QString)), &menu, SLOT(close())); + + widgetAction->setDefaultWidget(frame); + menu.addAction(widgetAction); + + QPoint pos(-menu.sizeHint().width()+pbSaveTheme->width(),-menu.sizeHint().height()); + menu.exec(pbSaveTheme->mapToGlobal(pos)); + leFilename->setFocus(); + } + + void ThemeHandler::saveNewSelected(const QString& filename) { + KConfig config(KGlobal::dirs()->locateLocal("appdata", "themes") + '/' + filename, KConfig::SimpleConfig); + emit (saveThemeRequested(config)); + emit info( i18n("New theme \"%1\" was saved.", filename) ); + + m_currentLocalTheme = filename; + m_themeList.append(config.name()); + + //enable the publish button so the newly created theme can be published + pbPublishTheme->setEnabled(true); + } + + /*! + opens the dialog to upload the currently selected local theme. + The publish button is only enabled if a local theme was loaded or one of the themes was modified and saved localy. + */ + void ThemeHandler::publishThemes() { + int ret = KMessageBox::questionYesNo(this, + i18n("Do you want to upload your theme %1 to public web server?").arg(m_currentLocalTheme), + i18n("Publish Theme")); + if (ret != KMessageBox::Yes) + return; + + // creating upload dialog + KNS3::UploadDialog dialog("labplot2_themes.knsrc", this); + dialog.setUploadFile(KGlobal::dirs()->locateLocal("appdata", "themes") + '/' + m_currentLocalTheme); + dialog.setUploadName(m_currentLocalTheme); + //dialog.setDescription(); TODO: allow the user to provide a short description for the theme to be uploaded + dialog.exec(); + } diff --cc src/kdefrontend/widgets/ThemesWidget.cpp index 0000000,e90c14a..17ff917 mode 000000,100644..100644 --- a/src/kdefrontend/widgets/ThemesWidget.cpp +++ b/src/kdefrontend/widgets/ThemesWidget.cpp @@@ -1,0 -1,103 +1,104 @@@ + /*************************************************************************** + File : ThemesWidget.cpp + Project : LabPlot + Description : widget for selecting themes + -------------------------------------------------------------------- + Copyright : (C) 2016 Prakriti Bhardwaj ([email protected]) + Copyright : (C) 2016 Alexander Semke ([email protected]) + + ***************************************************************************/ + + /*************************************************************************** + * * + * 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, write to the Free Software * + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * + * Boston, MA 02110-1301 USA * + * * + ***************************************************************************/ + #include "ThemesWidget.h" + #include "kdefrontend/ThemeHandler.h" + + #include <QListWidgetItem> + #include <QStandardItemModel> + #include <QFile> -#include <KStandardDirs> + ++#include <KGlobal> ++#include <KStandardDirs> + #include <KMessageBox> + #include <kdebug.h> -#include <knewstuff3/downloaddialog.h> ++#include <KNS3/DownloadDialog> + + /*! + \class ThemesWidget + \brief Widget for showing theme previews and for selecting a theme. + + \ingroup kdefrontend + */ + ThemesWidget::ThemesWidget(QWidget* parent) : QListView(parent) { + setSelectionMode(QAbstractItemView::SingleSelection); + setWordWrap(true); + setViewMode(QListWidget::IconMode); + setResizeMode(QListWidget::Adjust); + + //TODO: make this pixel-independent + setIconSize(QSize(200,200)); + setMaximumWidth(225); + + //show preview pixmaps + QStandardItemModel* mContentItemModel = new QStandardItemModel(this); + QStringList themeList = ThemeHandler::themes(); + QString themeImgPath = KGlobal::dirs()->findDirs("data", "labplot2/themes/screenshots/").first(); + QString tempPath; + + for (int i = 0; i < themeList.size(); ++i) { + QStandardItem* listItem = new QStandardItem(); + + tempPath = themeImgPath + themeList.at(i) + ".png"; + if(!QFile::exists(tempPath)) + tempPath = themeImgPath + "Unavailable.png"; + + listItem->setIcon(QIcon(QPixmap(tempPath))); + listItem->setText(themeList.at(i)); + listItem->setData(themeList.at(i), Qt::UserRole); + mContentItemModel->appendRow(listItem); + } + + //adding download themes option + QStandardItem* listItem = new QStandardItem(); + listItem->setIcon(QIcon::fromTheme("get-hot-new-stuff")); + listItem->setText("Download Themes"); + listItem->setData("file_download_theme", Qt::UserRole); + mContentItemModel->appendRow(listItem); + + setModel(mContentItemModel); + + //SLOTS + connect( this, SIGNAL(clicked(QModelIndex)), this, SLOT(applyClicked()) ); + } + + void ThemesWidget::applyClicked() { + QString themeName = currentIndex().data(Qt::UserRole).value<QString>(); + if(themeName=="file_download_theme") + this->downloadThemes(); + else + emit(themeSelected(themeName)); + } + + void ThemesWidget::downloadThemes() { + KNS3::DownloadDialog dialog("labplot2_themes.knsrc", this); + dialog.exec(); + foreach (const KNS3::Entry& e, dialog.changedEntries()) { + kDebug() << "Changed Entry: " << e.name(); + } + }
