add more spacing
[personal-kdebase.git] / apps / konsole / src / ManageProfilesDialog.h
blob20ca48369f100c9b9aa3179d6978154fb2c3f2be
1 /*
2 Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
20 #ifndef MANAGEPROFILESDIALOG_H
21 #define MANAGEPROFILESDIALOG_H
23 // Qt
24 #include <QtGui/QStyledItemDelegate>
25 #include <QtCore/QSet>
27 // KDE
28 #include <KDialog>
30 // Konsole
31 #include "Profile.h"
33 class QItemSelection;
34 class QShowEvent;
35 class QStandardItem;
36 class QStandardItemModel;
38 namespace Ui
40 class ManageProfilesDialog;
43 namespace Konsole
46 /**
47 * A dialog which lists the available types of profiles and allows
48 * the user to add new profiles, and remove or edit existing
49 * profile types.
51 class ManageProfilesDialog : public KDialog
53 Q_OBJECT
55 friend class FavoriteItemDelegate;
56 friend class ShortcutItemDelegate;
58 public:
59 /** Constructs a new profile type with the specified parent. */
60 ManageProfilesDialog(QWidget* parent = 0);
61 virtual ~ManageProfilesDialog();
63 /**
64 * Specifies whether the shorcut editor should be show.
65 * The shortcut editor allows shortcuts to be associated with
66 * profiles. When a shortcut is changed, the dialog will call
67 * SessionManager::instance()->setShortcut() to update the shortcut
68 * associated with the profile.
70 * By default the editor is visible.
72 void setShortcutEditorVisible(bool visible);
74 protected:
75 virtual void showEvent(QShowEvent* event);
77 private slots:
78 void deleteSelected();
79 void setSelectedAsDefault();
80 void newType();
81 void editSelected();
83 void itemDataChanged(QStandardItem* item);
85 // enables or disables Edit/Delete/Set as Default buttons when the
86 // selection changes
87 void tableSelectionChanged(const QItemSelection&);
89 void updateFavoriteStatus(Profile::Ptr profile, bool favorite);
91 void addItems(const Profile::Ptr);
92 void updateItems(const Profile::Ptr);
93 void removeItems(const Profile::Ptr);
95 private:
96 Profile::Ptr currentProfile() const;
97 QList<Profile::Ptr> selectedProfiles() const;
99 // updates the font of the items to match
100 // their default / non-default profile status
101 void updateDefaultItem();
102 void updateItemsForProfile(const Profile::Ptr profile, QList<QStandardItem*>& items) const;
103 // updates the profile table to be in sync with the
104 // session manager
105 void populateTable();
106 int rowForProfile(const Profile::Ptr info) const;
108 Ui::ManageProfilesDialog* _ui;
109 QStandardItemModel* _sessionModel;
111 static const int ProfileNameColumn = 0;
112 static const int FavoriteStatusColumn = 1;
113 static const int ShortcutColumn = 2;
114 static const int ProfileKeyRole = Qt::UserRole + 1;
115 static const int ShortcutRole = Qt::UserRole + 1;
118 class StyledBackgroundPainter
120 public:
121 static void drawBackground(QPainter* painter, const QStyleOptionViewItem& option,
122 const QModelIndex& index);
125 class FavoriteItemDelegate : public QStyledItemDelegate
127 public:
128 FavoriteItemDelegate(QObject* parent = 0);
130 virtual bool editorEvent(QEvent* event,QAbstractItemModel* model,
131 const QStyleOptionViewItem& option,const QModelIndex& index);
132 virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
133 const QModelIndex& index) const;
136 class ShortcutItemDelegate : public QStyledItemDelegate
138 Q_OBJECT
140 public:
141 ShortcutItemDelegate(QObject* parent = 0);
143 virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const;
144 virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
145 const QModelIndex& index) const;
146 virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
147 const QModelIndex& index) const;
149 private slots:
150 void editorModified(const QKeySequence& keys);
152 private:
153 mutable QSet<QWidget*> _modifiedEditors;
154 mutable QSet<QModelIndex> _itemsBeingEdited;
158 #endif // MANAGEPROFILESDIALOG_H