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
20 #ifndef MANAGEPROFILESDIALOG_H
21 #define MANAGEPROFILESDIALOG_H
24 #include <QtGui/QStyledItemDelegate>
25 #include <QtCore/QSet>
36 class QStandardItemModel
;
40 class ManageProfilesDialog
;
47 * A dialog which lists the available types of profiles and allows
48 * the user to add new profiles, and remove or edit existing
51 class ManageProfilesDialog
: public KDialog
55 friend class FavoriteItemDelegate
;
56 friend class ShortcutItemDelegate
;
59 /** Constructs a new profile type with the specified parent. */
60 ManageProfilesDialog(QWidget
* parent
= 0);
61 virtual ~ManageProfilesDialog();
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
);
75 virtual void showEvent(QShowEvent
* event
);
78 void deleteSelected();
79 void setSelectedAsDefault();
83 void itemDataChanged(QStandardItem
* item
);
85 // enables or disables Edit/Delete/Set as Default buttons when the
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
);
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
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
121 static void drawBackground(QPainter
* painter
, const QStyleOptionViewItem
& option
,
122 const QModelIndex
& index
);
125 class FavoriteItemDelegate
: public QStyledItemDelegate
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
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;
150 void editorModified(const QKeySequence
& keys
);
153 mutable QSet
<QWidget
*> _modifiedEditors
;
154 mutable QSet
<QModelIndex
> _itemsBeingEdited
;
158 #endif // MANAGEPROFILESDIALOG_H