ManageProfilesDialog.h 4.79 KB
Newer Older
1
/*
2
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

    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.
*/

20
21
#ifndef MANAGEPROFILESDIALOG_H
#define MANAGEPROFILESDIALOG_H
22
23

// Qt
24
#include <QtGui/QStyledItemDelegate>
25
#include <QtCore/QSet>
26
27
28
29

// KDE
#include <KDialog>

30
31
32
// Konsole
#include "Profile.h"

33
class QItemSelection;
34
class QShowEvent;
35
36
37
38
39
class QStandardItem;
class QStandardItemModel;

namespace Ui
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
40
class ManageProfilesDialog;
Stephan Binner's avatar
Stephan Binner committed
41
}
42
43
44
45

namespace Konsole
{
/**
46
47
48
 * A dialog which lists the available types of profiles and allows
 * the user to add new profiles, and remove or edit existing
 * profile types.
49
 */
50
class KONSOLEPRIVATE_EXPORT ManageProfilesDialog : public KDialog
51
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
52
    Q_OBJECT
53

Kurt Hindenburg's avatar
Kurt Hindenburg committed
54
55
    friend class FavoriteItemDelegate;
    friend class ShortcutItemDelegate;
Robert Knight's avatar
   
Robert Knight committed
56

57
public:
58
    /** Constructs a new profile type with the specified parent. */
59
    explicit ManageProfilesDialog(QWidget* parent = 0);
60
    virtual ~ManageProfilesDialog();
61

Jekyll Wu's avatar
Jekyll Wu committed
62
    /**
63
     * Specifies whether the shorcut editor should be show.
Jekyll Wu's avatar
Jekyll Wu committed
64
     * The shortcut editor allows shortcuts to be associated with
65
66
67
68
69
70
71
     * profiles.  When a shortcut is changed, the dialog will call
     * SessionManager::instance()->setShortcut() to update the shortcut
     * associated with the profile.
     *
     * By default the editor is visible.
     */
    void setShortcutEditorVisible(bool visible);
Robert Knight's avatar
   
Robert Knight committed
72

73
74
75
protected:
    virtual void showEvent(QShowEvent* event);

76
77
78
private slots:
    void deleteSelected();
    void setSelectedAsDefault();
Jekyll Wu's avatar
Jekyll Wu committed
79
    void createProfile();
80
    void editSelected();
81
82
    void moveUpSelected();
    void moveDownSelected();
83

84
85
    void itemDataChanged(QStandardItem* item);

Jekyll Wu's avatar
Jekyll Wu committed
86
    // enables or disables Edit/Delete/Set as Default buttons when the
87
88
89
    // selection changes
    void tableSelectionChanged(const QItemSelection&);

90
    void updateFavoriteStatus(Profile::Ptr profile, bool favorite);
Robert Knight's avatar
   
Robert Knight committed
91

92
93
94
95
    void addItems(const Profile::Ptr);
    void updateItems(const Profile::Ptr);
    void removeItems(const Profile::Ptr);

96
private:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
97
98
    Profile::Ptr currentProfile() const;
    QList<Profile::Ptr> selectedProfiles() const;
99
    bool isProfileDeletable(Profile::Ptr profile) const;
100
101
102

    // updates the font of the items to match
    // their default / non-default profile status
Kurt Hindenburg's avatar
Kurt Hindenburg committed
103
    void updateDefaultItem();
104
    void updateItemsForProfile(const Profile::Ptr profile, QList<QStandardItem*>& items) const;
Jekyll Wu's avatar
Jekyll Wu committed
105
    // updates the profile table to be in sync with the
106
107
    // session manager
    void populateTable();
Jekyll Wu's avatar
Jekyll Wu committed
108
    int rowForProfile(const Profile::Ptr profile) const;
109

110
    Ui::ManageProfilesDialog* _ui;
111
    QStandardItemModel* _sessionModel;
Robert Knight's avatar
   
Robert Knight committed
112

113
    static const int ProfileNameColumn = 0;
Robert Knight's avatar
   
Robert Knight committed
114
    static const int FavoriteStatusColumn = 1;
115
    static const int ShortcutColumn = 2;
Robert Knight's avatar
   
Robert Knight committed
116
117
    static const int ProfileKeyRole = Qt::UserRole + 1;
    static const int ShortcutRole = Qt::UserRole + 1;
118
119
};

Kurt Hindenburg's avatar
Kurt Hindenburg committed
120
class StyledBackgroundPainter
121
122
{
public:
123
    static void drawBackground(QPainter* painter, const QStyleOptionViewItem& option,
Kurt Hindenburg's avatar
Kurt Hindenburg committed
124
                               const QModelIndex& index);
125
126
127
128
129
};

class FavoriteItemDelegate : public QStyledItemDelegate
{
public:
130
    explicit FavoriteItemDelegate(QObject* parent = 0);
131

Kurt Hindenburg's avatar
Kurt Hindenburg committed
132
133
134
135
    virtual bool editorEvent(QEvent* event, QAbstractItemModel* model,
                             const QStyleOptionViewItem& option, const QModelIndex& index);
    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;
136
137
};

138
139
class ShortcutItemDelegate : public QStyledItemDelegate
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
140
    Q_OBJECT
141
142

public:
143
    explicit ShortcutItemDelegate(QObject* parent = 0);
144

145
    virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
146
147
148
149
    virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
                                  const QModelIndex& index) const;
    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;
150
151

private slots:
152
    void editorModified(const QKeySequence& keys);
153
154

private:
155
156
    mutable QSet<QWidget*> _modifiedEditors;
    mutable QSet<QModelIndex> _itemsBeingEdited;
157
};
Stephan Binner's avatar
Stephan Binner committed
158
}
159
#endif // MANAGEPROFILESDIALOG_H
160