File indexing completed on 2024-05-12 07:41:29

0001 /*
0002     File                 : TemplateHandler.h
0003     Project              : LabPlot
0004     Description          : Widget for handling saving and loading of templates
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2012 Stefan Gerlach <stefan.gerlach@uni-konstanz.de>
0007     SPDX-FileCopyrightText: 2012-2022 Alexander Semke <alexander.semke@web.de>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef TEMPLATEHANDLER_H
0012 #define TEMPLATEHANDLER_H
0013 
0014 #include <QWidget>
0015 
0016 class QMenu;
0017 class QToolButton;
0018 class KConfig;
0019 
0020 class TemplateHandler : public QWidget {
0021     Q_OBJECT
0022 
0023 public:
0024     TemplateHandler(QWidget* parent, const QString& className, bool alignRight = true);
0025     void setClassName(const QString&);
0026 
0027     void setToolButtonStyle(Qt::ToolButtonStyle);
0028     void setSaveDefaultAvailable(bool);
0029     void setLoadAvailable(bool);
0030 
0031     KConfig config(const QString& name);
0032     static QString templateName(const KConfig&);
0033     QStringList templateNames() const;
0034 
0035 private:
0036     void retranslateUi();
0037     bool eventFilter(QObject*, QEvent*) override;
0038 
0039     QString m_dirName;
0040     QString m_className;
0041 
0042     QMenu* m_textPositionMenu{nullptr};
0043     QToolButton* m_tbLoad;
0044     QToolButton* m_tbSave;
0045     QToolButton* m_tbSaveDefault;
0046     //  QToolButton* m_tbCopy;
0047     //  QToolButton* m_tbPaste;
0048 
0049 private Q_SLOTS:
0050     void loadMenu();
0051     void saveMenu();
0052     void loadMenuSelected(QAction*);
0053     void saveMenuSelected(QAction*);
0054     void saveNewSelected(const QString&);
0055     void saveDefaults();
0056     void updateTextPosition(QAction*);
0057 
0058 Q_SIGNALS:
0059     void loadConfigRequested(KConfig&);
0060     void saveConfigRequested(KConfig&);
0061     void info(const QString&);
0062 };
0063 
0064 #endif