1 | /* |
2 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> |
3 | |
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. |
8 | |
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. |
13 | |
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. |
18 | */ |
19 | |
20 | #ifndef EDITPROFILEDIALOG_H |
21 | #define EDITPROFILEDIALOG_H |
22 | |
23 | // Qt |
24 | #include <QAbstractItemDelegate> |
25 | #include <QtCore/QHash> |
26 | #include <QtCore/QPointer> |
27 | |
28 | // KDE |
29 | #include <KDialog> |
30 | |
31 | // Konsole |
32 | #include "Profile.h" |
33 | #include "Enumeration.h" |
34 | #include "ColorScheme.h" |
35 | #include "ColorSchemeEditor.h" |
36 | |
37 | class QAbstractButton; |
38 | class QItemSelectionModel; |
39 | class QTextCodec; |
40 | |
41 | namespace Ui |
42 | { |
43 | class EditProfileDialog; |
44 | } |
45 | |
46 | namespace Konsole |
47 | { |
48 | /** |
49 | * A dialog which allows the user to edit a profile. |
50 | * After the dialog is created, it can be initialized with the settings |
51 | * for a profile using setProfile(). When the user makes changes to the |
52 | * dialog and accepts the changes, the dialog will update the |
53 | * profile in the SessionManager by calling the SessionManager's |
54 | * changeProfile() method. |
55 | * |
56 | * Some changes made in the dialog are preview-only changes which cause |
57 | * the SessionManager's changeProfile() method to be called with |
58 | * the persistent argument set to false. These changes are then |
59 | * un-done when the dialog is closed. |
60 | */ |
61 | class KONSOLEPRIVATE_EXPORT EditProfileDialog : public KDialog |
62 | { |
63 | Q_OBJECT |
64 | |
65 | public: |
66 | /** Constructs a new dialog with the specified parent. */ |
67 | explicit EditProfileDialog(QWidget* parent = 0); |
68 | virtual ~EditProfileDialog(); |
69 | |
70 | /** |
71 | * Initializes the dialog with the settings for the specified session |
72 | * type. |
73 | * |
74 | * When the dialog closes, the profile will be updated in the SessionManager |
75 | * with the altered settings. |
76 | * |
77 | * @param profile The profile to be edited |
78 | */ |
79 | void setProfile(Profile::Ptr profile); |
80 | |
81 | /** |
82 | * Selects the text in the profile name edit area. |
83 | * When the dialog is being used to create a new profile, |
84 | * this can be used to draw the user's attention to the profile name |
85 | * and make it easy for them to change it. |
86 | */ |
87 | void selectProfileName(); |
88 | const Profile::Ptr lookupProfile() const; |
89 | |
90 | public slots: |
91 | // reimplemented |
92 | virtual void accept(); |
93 | // reimplemented |
94 | virtual void reject(); |
95 | |
96 | protected: |
97 | virtual bool eventFilter(QObject* watched , QEvent* event); |
98 | |
99 | private slots: |
100 | // sets up the specified tab page if necessary |
101 | void preparePage(int); |
102 | |
103 | // saves changes to profile |
104 | void save(); |
105 | |
106 | // general page |
107 | void selectInitialDir(); |
108 | void selectIcon(); |
109 | |
110 | void profileNameChanged(const QString& text); |
111 | void initialDirChanged(const QString& text); |
112 | void startInSameDir(bool); |
113 | void commandChanged(const QString& text); |
114 | void tabTitleFormatChanged(const QString& text); |
115 | void remoteTabTitleFormatChanged(const QString& text); |
116 | |
117 | void terminalColumnsEntryChanged(int); |
118 | void terminalRowsEntryChanged(int); |
119 | void showTerminalSizeHint(bool); |
120 | void showEnvironmentEditor(); |
121 | void silenceSecondsChanged(int); |
122 | |
123 | // appearance page |
124 | void setFontSize(double pointSize); |
125 | void setFontInputValue(const QFont&); |
126 | void setAntialiasText(bool enable); |
127 | void setBoldIntense(bool enable); |
128 | void showFontDialog(); |
129 | void newColorScheme(); |
130 | void editColorScheme(); |
131 | void saveColorScheme(const ColorScheme& scheme, bool isNewScheme); |
132 | void removeColorScheme(); |
133 | void colorSchemeSelected(); |
134 | void previewColorScheme(const QModelIndex& index); |
135 | void fontSelected(const QFont&); |
136 | void toggleMouseWheelZoom(bool enable); |
137 | |
138 | // scrolling page |
139 | void historyModeChanged(Enum::HistoryModeEnum mode); |
140 | |
141 | void historySizeChanged(int); |
142 | |
143 | void hideScrollBar(); |
144 | void showScrollBarLeft(); |
145 | void showScrollBarRight(); |
146 | |
147 | void scrollFullPage(); |
148 | void scrollHalfPage(); |
149 | |
150 | // keyboard page |
151 | void editKeyBinding(); |
152 | void newKeyBinding(); |
153 | void keyBindingSelected(); |
154 | void removeKeyBinding(); |
155 | |
156 | // mouse page |
157 | void toggleUnderlineLinks(bool); |
158 | void toggleOpenLinksByDirectClick(bool); |
159 | void toggleCtrlRequiredForDrag(bool); |
160 | void toggleCopyTextToClipboard(bool); |
161 | void toggleTrimTrailingSpacesInSelectedText(bool); |
162 | void pasteFromX11Selection(); |
163 | void pasteFromClipboard(); |
164 | |
165 | void TripleClickModeChanged(int); |
166 | void wordCharactersChanged(const QString&); |
167 | |
168 | // advanced page |
169 | void toggleBlinkingText(bool); |
170 | void toggleFlowControl(bool); |
171 | void togglebidiRendering(bool); |
172 | void lineSpacingChanged(int); |
173 | void toggleBlinkingCursor(bool); |
174 | |
175 | void setCursorShape(int); |
176 | void autoCursorColor(); |
177 | void customCursorColor(); |
178 | void customCursorColorChanged(const QColor&); |
179 | void setDefaultCodec(QTextCodec*); |
180 | |
181 | // apply the first previewed changes stored up by delayedPreview() |
182 | void delayedPreviewActivate(); |
183 | |
184 | private: |
185 | // initialize various pages of the dialog |
186 | void setupGeneralPage(const Profile::Ptr profile); |
187 | void setupTabsPage(const Profile::Ptr profile); |
188 | void setupAppearancePage(const Profile::Ptr profile); |
189 | void setupKeyboardPage(const Profile::Ptr profile); |
190 | void setupScrollingPage(const Profile::Ptr profile); |
191 | void setupAdvancedPage(const Profile::Ptr profile); |
192 | void setupMousePage(const Profile::Ptr info); |
193 | |
194 | void updateColorSchemeList(bool selectCurrentScheme = false); |
195 | void updateColorSchemeButtons(); |
196 | void updateKeyBindingsList(bool selectCurrentTranslator = false); |
197 | void updateKeyBindingsButtons(); |
198 | |
199 | void showColorSchemeEditor(bool isNewScheme); |
200 | void closeColorSchemeEditor(); |
201 | void showKeyBindingEditor(bool newTranslator); |
202 | |
203 | void preview(int property , const QVariant& value); |
204 | void delayedPreview(int property , const QVariant& value); |
205 | void unpreview(int property); |
206 | void unpreviewAll(); |
207 | void enableIfNonEmptySelection(QWidget* widget, QItemSelectionModel* selectionModel); |
208 | |
209 | void updateCaption(const Profile::Ptr profile); |
210 | void updateTransparencyWarning(); |
211 | |
212 | // Update _tempProfile in a way of respecting the apply button. |
213 | // When used with some previewed property, this method should |
214 | // always come after the preview operation. |
215 | void updateTempProfileProperty(Profile::Property, const QVariant& value); |
216 | |
217 | // helper method for creating an empty & hidden profile and assigning |
218 | // it to _tempProfile. |
219 | void createTempProfile(); |
220 | |
221 | // Enable or disable apply button, used only within |
222 | // updateTempProfileProperty(). |
223 | void updateButtonApply(); |
224 | |
225 | static QString groupProfileNames(const ProfileGroup::Ptr group, int maxLength = -1); |
226 | |
227 | struct RadioOption { |
228 | QAbstractButton* button; |
229 | int value; |
230 | const char* slot; |
231 | }; |
232 | void setupRadio(RadioOption* possibilities, int actual); |
233 | struct BooleanOption { |
234 | QAbstractButton* button; |
235 | Profile::Property property; |
236 | const char* slot; |
237 | }; |
238 | void setupCheckBoxes(BooleanOption* options , const Profile::Ptr profile); |
239 | |
240 | Ui::EditProfileDialog* _ui; |
241 | Profile::Ptr _tempProfile; |
242 | Profile::Ptr _profile; |
243 | |
244 | // keeps track of pages which need to be updated to match the current |
245 | // profile. all elements in this vector are set to true when the |
246 | // profile is changed and individual elements are set to false |
247 | // after an update by a call to ensurePageLoaded() |
248 | QVector<bool> _pageNeedsUpdate; |
249 | QHash<int, QVariant> _previewedProperties; |
250 | |
251 | QHash<int, QVariant> _delayedPreviewProperties; |
252 | QTimer* _delayedPreviewTimer; |
253 | |
254 | ColorSchemeEditor* _colorDialog; |
255 | }; |
256 | |
257 | /** |
258 | * A delegate which can display and edit color schemes in a view. |
259 | */ |
260 | class ColorSchemeViewDelegate : public QAbstractItemDelegate |
261 | { |
262 | Q_OBJECT |
263 | |
264 | public: |
265 | explicit ColorSchemeViewDelegate(QObject* parent = 0); |
266 | |
267 | // reimplemented |
268 | virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, |
269 | const QModelIndex& index) const; |
270 | virtual QSize sizeHint(const QStyleOptionViewItem& option, |
271 | const QModelIndex& index) const; |
272 | }; |
273 | } |
274 | |
275 | #endif // EDITPROFILEDIALOG_H |
276 | |