File: kf5_utils.h

package info (click to toggle)
qtcurve 1.9-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,468 kB
  • sloc: cpp: 70,269; perl: 123; sh: 122; xml: 46; makefile: 14
file content (96 lines) | stat: -rw-r--r-- 3,310 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*****************************************************************************
 *   Copyright 2015 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
 *                                                                           *
 *   This program 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.1 of the    *
 *   License, or (at your option) version 3, or any later version accepted   *
 *   by the membership of KDE e.V. (or its successor approved by the         *
 *   membership of KDE e.V.), which shall act as a proxy defined in          *
 *   Section 6 of version 3 of the license.                                  *
 *                                                                           *
 *   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       *
 *   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,                                *
 *   see <http://www.gnu.org/licenses/>.                                     *
 *****************************************************************************/

#ifndef __COMMON_KF5_UTILS_H__
#define __COMMON_KF5_UTILS_H__

#include <qtcurve-utils/utils.h>

#include <kiconengine.h>
#include <kiconloader.h>

#include <QStandardPaths>
#include <QDir>
#include <QDialog>

class QDialogButtonBox;
class QValidator;
class QLineEdit;
class QLabel;

namespace QtCurve {

QDialogButtonBox *createDialogButtonBox(QDialog *dialog);

class InputDialog : public QDialog {
    Q_OBJECT
public:
    explicit InputDialog(QWidget *parent=nullptr, Qt::WindowFlags=0);

    void setTitle(const QString &title);
    void setLabelText(const QString &label);
    void setText(const QString &text);
    void setValidator(QValidator *validator);

    QString getLabelText();
    QString getText();

    static QString getText(QWidget *parent, const QString &title,
                           const QString &label, const QString &text,
                           QValidator *validator=nullptr,
                           bool *ok=nullptr, Qt::WindowFlags flags=0);

private:
    void checkValid(const QString &text);

private:
    QLabel *m_label;
    QLineEdit *m_text;
    QDialogButtonBox *m_buttonBox;
    QValidator *m_validator;
};

static inline QIcon
loadKIcon(const QString &name)
{
    return QIcon(new KIconEngine(name, KIconLoader::global()));
}

// TODO probably merge with utils/dirs
static inline QString
saveLocation(QStandardPaths::StandardLocation type, const char *suffix)
{
    QString path = QStandardPaths::writableLocation(type);
    QTC_RET_IF_FAIL(!path.isEmpty(), path);
    path += '/' + QString::fromUtf8(suffix);
    QDir().mkpath(path);
    return path;
}

static inline QString
qtcSaveDir()
{
    return saveLocation(QStandardPaths::GenericDataLocation, "QtCurve/");
}

}

#endif