File indexing completed on 2024-04-28 17:04:34
0001 /***************************************************************************** 0002 * Copyright 2015 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #ifndef __COMMON_KF5_UTILS_H__ 0023 #define __COMMON_KF5_UTILS_H__ 0024 0025 #include <qtcurve-utils/utils.h> 0026 0027 #include <kiconengine.h> 0028 #include <kiconloader.h> 0029 0030 #include <QStandardPaths> 0031 #include <QDir> 0032 #include <QDialog> 0033 0034 class QDialogButtonBox; 0035 class QValidator; 0036 class QLineEdit; 0037 class QLabel; 0038 0039 namespace QtCurve { 0040 0041 QDialogButtonBox *createDialogButtonBox(QDialog *dialog); 0042 0043 class InputDialog : public QDialog { 0044 Q_OBJECT 0045 public: 0046 explicit InputDialog(QWidget *parent=nullptr, Qt::WindowFlags=0); 0047 0048 void setTitle(const QString &title); 0049 void setLabelText(const QString &label); 0050 void setText(const QString &text); 0051 void setValidator(QValidator *validator); 0052 0053 QString getLabelText(); 0054 QString getText(); 0055 0056 static QString getText(QWidget *parent, const QString &title, 0057 const QString &label, const QString &text, 0058 QValidator *validator=nullptr, 0059 bool *ok=nullptr, Qt::WindowFlags flags=0); 0060 0061 private: 0062 void checkValid(const QString &text); 0063 0064 private: 0065 QLabel *m_label; 0066 QLineEdit *m_text; 0067 QDialogButtonBox *m_buttonBox; 0068 QValidator *m_validator; 0069 }; 0070 0071 static inline QIcon 0072 loadKIcon(const QString &name) 0073 { 0074 return QIcon(new KIconEngine(name, KIconLoader::global())); 0075 } 0076 0077 // TODO probably merge with utils/dirs 0078 static inline QString 0079 saveLocation(QStandardPaths::StandardLocation type, const char *suffix) 0080 { 0081 QString path = QStandardPaths::writableLocation(type); 0082 QTC_RET_IF_FAIL(!path.isEmpty(), path); 0083 path += '/' + QString::fromUtf8(suffix); 0084 QDir().mkpath(path); 0085 return path; 0086 } 0087 0088 static inline QString 0089 qtcSaveDir() 0090 { 0091 return saveLocation(QStandardPaths::GenericDataLocation, "QtCurve/"); 0092 } 0093 0094 } 0095 0096 #endif