EditProfileDialog.h 8.67 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 EDITPROFILEDIALOG_H
#define EDITPROFILEDIALOG_H
22 23

// Qt
Dirk Mueller's avatar
Dirk Mueller committed
24 25 26 27
#include <QtGui/QAbstractItemDelegate>
#include <QtCore/QPair>
#include <QtCore/QHash>
#include <QtCore/QSet>
28
#include <QtCore/QPointer>
29 30 31 32

// KDE
#include <KDialog>

Jekyll Wu's avatar
Jekyll Wu committed
33
// Konsole
34 35
#include "Profile.h"

36
class QAbstractButton;
Robert Knight's avatar
 
Robert Knight committed
37
class QItemSelectionModel;
38
class QTextCodec;
39
class QTimeLine;
40

41 42
namespace Ui
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
43
class EditProfileDialog;
Stephan Binner's avatar
Stephan Binner committed
44
}
45 46 47 48 49

namespace Konsole
{

/**
50
 * A dialog which allows the user to edit a profile.
Jekyll Wu's avatar
Jekyll Wu committed
51
 * After the dialog is created, it can be initialized with the settings
Jekyll Wu's avatar
Jekyll Wu committed
52
 * for a profile using setProfile().  When the user makes changes to the
53
 * dialog and accepts the changes, the dialog will update the
Jekyll Wu's avatar
Jekyll Wu committed
54
 * profile in the SessionManager by calling the SessionManager's
55 56 57 58
 * changeProfile() method.
 *
 * Some changes made in the dialog are preview-only changes which cause
 * the SessionManager's changeProfile() method to be called with
59
 * the persistent argument set to false.  These changes are then
60
 * un-done when the dialog is closed.
61
 */
62
class KONSOLEPRIVATE_EXPORT EditProfileDialog : public KDialog
63
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
64
    Q_OBJECT
65 66 67

public:
    /** Constructs a new dialog with the specified parent. */
68 69
    EditProfileDialog(QWidget* parent = 0);
    virtual ~EditProfileDialog();
70 71

    /**
Jekyll Wu's avatar
Jekyll Wu committed
72
     * Initializes the dialog with the settings for the specified session
73 74
     * type.
     *
75 76 77
     * When the dialog closes, the profile will be updated in the SessionManager
     * with the altered settings.
     *
78
     * @param profile The profile to be edited
79
     */
80
    void setProfile(Profile::Ptr profile);
81

Jekyll Wu's avatar
Jekyll Wu committed
82 83
    /**
     * Selects the text in the profile name edit area.
Robert Knight's avatar
 
Robert Knight committed
84 85 86 87 88 89
     * When the dialog is being used to create a new profile,
     * this can be used to draw the user's attention to the profile name
     * and make it easy for them to change it.
     */
    void selectProfileName();

90
public slots:
91
    // reimplemented
92
    virtual void accept();
Jekyll Wu's avatar
Jekyll Wu committed
93
    // reimplemented
94
    virtual void reject();
95

96 97 98
protected:
    virtual bool eventFilter(QObject* watched , QEvent* event);

99
private slots:
100
    // sets up the specified tab page if necessary
Robert Knight's avatar
 
Robert Knight committed
101
    void preparePage(int);
102

103 104 105
    // saves changes to profile
    void save();

106 107
    // general page
    void selectInitialDir();
108 109 110 111
    void selectIcon();

    void profileNameChanged(const QString& text);
    void initialDirChanged(const QString& text);
112
    void startInSameDir(bool);
113 114 115
    void commandChanged(const QString& text);
    void tabTitleFormatChanged(const QString& text);
    void remoteTabTitleFormatChanged(const QString& text);
116

117 118
    void insertTabTitleText(const QString& text);
    void insertRemoteTabTitleText(const QString& text);
119

120
    void showTerminalSizeHint(bool);
121
    void saveGeometryOnExit(bool);
122
    void showEnvironmentEditor();
123
    void silenceSecondsChanged(int);
124 125
    void tabBarVisibilityChanged(int);
    void tabBarPositionChanged(int);
126
    void newTabBehaviorChanged(int);
127
    void showNewTabButton(bool);
128

129
    // appearance page
130
    void setFontSize(int pointSize);
131 132
    void setFontSliderRange(const QFont&);
    void setFontSliderValue(const QFont&);
133
    void setAntialiasText(bool enable);
134
    void setBoldIntense(bool enable);
135
    void showFontDialog();
136 137 138
    void newColorScheme();
    void editColorScheme();
    void removeColorScheme();
139
    void colorSchemeSelected();
140
    void previewColorScheme(const QModelIndex& index);
141
    void fontSelected(const QFont&);
142

143 144
    void colorSchemeAnimationUpdate();

145 146 147 148
    // scrolling page
    void noScrollBack();
    void fixedScrollBack();
    void unlimitedScrollBack();
149

150 151 152 153 154 155
    void scrollBackLinesChanged(int);

    void hideScrollBar();
    void showScrollBarLeft();
    void showScrollBarRight();

156 157 158 159 160 161
    // keyboard page
    void editKeyBinding();
    void newKeyBinding();
    void keyBindingSelected();
    void removeKeyBinding();

162 163 164 165
    // advanced page
    void toggleBlinkingText(bool);
    void toggleFlowControl(bool);
    void toggleResizeWindow(bool);
166
    void togglebidiRendering(bool);
167
    void toggleBlinkingCursor(bool);
168
    void TripleClickModeChanged(int);
169
    void toggleUnderlineLinks(bool);
170

171 172 173 174 175
    void setCursorShape(int);
    void autoCursorColor();
    void customCursorColor();
    void customCursorColorChanged(const QColor&);
    void wordCharactersChanged(const QString&);
176
    void setDefaultCodec(QTextCodec*);
177

178 179 180
    // apply the first previewed changes stored up by delayedPreview()
    void delayedPreviewActivate();

181 182
private:
    // initialize various pages of the dialog
183 184 185 186 187 188
    void setupGeneralPage(const Profile::Ptr info);
    void setupTabsPage(const Profile::Ptr info);
    void setupAppearancePage(const Profile::Ptr info);
    void setupKeyboardPage(const Profile::Ptr info);
    void setupScrollingPage(const Profile::Ptr info);
    void setupAdvancedPage(const Profile::Ptr info);
189

190
    void updateColorSchemeList(bool selectCurrentScheme = false);
Robert Knight's avatar
 
Robert Knight committed
191
    void updateColorSchemeButtons();
192
    void updateKeyBindingsList(bool selectCurrentTranslator = false);
Robert Knight's avatar
 
Robert Knight committed
193
    void updateKeyBindingsButtons();
194

195
    void showColorSchemeEditor(bool newScheme);
196 197
    void showKeyBindingEditor(bool newTranslator);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
198
    void changeCheckedItem(QAbstractItemModel* mode,  const QModelIndex& to);
199

Robert Knight's avatar
Robert Knight committed
200
    void preview(int property , const QVariant& value);
201
    void delayedPreview(int property , const QVariant& value);
202
    void unpreview(int property);
203
    void unpreviewAll();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
204
    void enableIfNonEmptySelection(QWidget* widget, QItemSelectionModel* selectionModel);
205

206
    void updateCaption(const Profile::Ptr profile);
Robert Knight's avatar
 
Robert Knight committed
207 208
    void updateTransparencyWarning();

209 210 211 212 213
    // Update _tempProfile in a way of respecting the apply button.
    // When used with some previewed property, this method should
    // always come after the preview operation.
    void updateTempProfileProperty(Profile::Property, const QVariant& value);

214 215 216 217
    // helper method for creating an empty & hidden profile and assigning
    // it to _tempProfile.
    void createTempProfile();

Jekyll Wu's avatar
Jekyll Wu committed
218
    // Enable or disable apply button, used only within
219 220 221
    // updateTempProfileProperty().
    void updateButtonApply();

222 223
    static QString groupProfileNames(const ProfileGroup::Ptr group, int maxLength = -1);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
224 225 226 227
    struct RadioOption {
        QAbstractButton* button;
        int value;
        const char* slot;
Robert Knight's avatar
Robert Knight committed
228
    };
229
    void setupRadio(RadioOption* possibilities, int actual);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
230 231 232 233
    struct BooleanOption {
        QAbstractButton* button;
        Profile::Property property;
        const char* slot;
Robert Knight's avatar
Robert Knight committed
234
    };
235
    void setupCheckBoxes(BooleanOption* options , const Profile::Ptr profile);
236

237
    const Profile::Ptr lookupProfile() const;
238

239
    Ui::EditProfileDialog* _ui;
240
    Profile::Ptr _tempProfile;
241
    Profile::Ptr _profile;
242

243
    // keeps track of pages which need to be updated to match the current
Jekyll Wu's avatar
Jekyll Wu committed
244 245
    // profile.  all elements in this vector are set to true when the
    // profile is changed and individual elements are set to false
246 247
    // after an update by a call to ensurePageLoaded()
    QVector<bool> _pageNeedsUpdate;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
248
    QHash<int, QVariant> _previewedProperties;
249

Robert Knight's avatar
 
Robert Knight committed
250
    QTimeLine* _colorSchemeAnimationTimeLine;
251

Kurt Hindenburg's avatar
Kurt Hindenburg committed
252
    QHash<int, QVariant> _delayedPreviewProperties;
253
    QTimer* _delayedPreviewTimer;
254 255 256 257 258 259 260
};

/**
 * A delegate which can display and edit color schemes in a view.
 */
class ColorSchemeViewDelegate : public QAbstractItemDelegate
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
261
    Q_OBJECT
262

263 264 265 266 267 268
public:
    ColorSchemeViewDelegate(QObject* parent = 0);

    // reimplemented
    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
269 270
    virtual QSize sizeHint(const QStyleOptionViewItem& option,
                           const QModelIndex& index) const;
271

Jekyll Wu's avatar
Jekyll Wu committed
272
    /**
273 274 275 276
     * Sets the timeline used to control the entry animation
     * for this delegate.
     *
     * During a call to paint(), the value of the timeLine is used to
Jekyll Wu's avatar
Jekyll Wu committed
277
     * determine how to render the item ( with 0 being the beginning
278 279
     * of the animation and 1.0 being the end )
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
280
    void setEntryTimeLine(QTimeLine* timeLine);
281 282 283 284

private:
    QPointer<QTimeLine> _entryTimeLine;

285 286
};

Stephan Binner's avatar
Stephan Binner committed
287
}
288

289
#endif // EDITPROFILEDIALOG_H