EditProfileDialog.h 8.61 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
24
#include <QAbstractItemDelegate>
Dirk Mueller's avatar
Dirk Mueller committed
25
#include <QtCore/QHash>
26
#include <QtCore/QPointer>
27 28

// KDE
Laurent Montel's avatar
Laurent Montel committed
29
#include <QDialog>
30

Jekyll Wu's avatar
Jekyll Wu committed
31
// Konsole
32
#include "Profile.h"
33
#include "Enumeration.h"
34 35
#include "ColorScheme.h"
#include "ColorSchemeEditor.h"
36

37
class QAbstractButton;
Robert Knight's avatar
 
Robert Knight committed
38
class QItemSelectionModel;
39
class QTextCodec;
Laurent Montel's avatar
Laurent Montel committed
40
class QDialogButtonBox;
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

namespace Konsole
{
/**
49
 * A dialog which allows the user to edit a profile.
Jekyll Wu's avatar
Jekyll Wu committed
50
 * After the dialog is created, it can be initialized with the settings
Jekyll Wu's avatar
Jekyll Wu committed
51
 * for a profile using setProfile().  When the user makes changes to the
52
 * dialog and accepts the changes, the dialog will update the
Jekyll Wu's avatar
Jekyll Wu committed
53
 * profile in the SessionManager by calling the SessionManager's
54 55 56 57
 * changeProfile() method.
 *
 * Some changes made in the dialog are preview-only changes which cause
 * 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
 */
Laurent Montel's avatar
Laurent Montel committed
61
class KONSOLEPRIVATE_EXPORT EditProfileDialog : public QDialog
62
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
63
    Q_OBJECT
64 65 66

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

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

Jekyll Wu's avatar
Jekyll Wu committed
81 82
    /**
     * Selects the text in the profile name edit area.
Robert Knight's avatar
 
Robert Knight committed
83 84 85 86 87
     * 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();
88
    const Profile::Ptr lookupProfile() const;
Robert Knight's avatar
 
Robert Knight committed
89

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 terminalColumnsEntryChanged(int);
    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 showAllFontsButtonWarning(bool enable);
127
    void setAntialiasText(bool enable);
128
    void setBoldIntense(bool enable);
129
    void showFontDialog();
130 131
    void newColorScheme();
    void editColorScheme();
132
    void saveColorScheme(const ColorScheme& scheme, bool isNewScheme);
133
    void removeColorScheme();
134
    void colorSchemeSelected();
135
    void previewColorScheme(const QModelIndex& index);
136
    void fontSelected(const QFont&);
137
    void toggleMouseWheelZoom(bool enable);
138

139
    // scrolling page
140
    void historyModeChanged(Enum::HistoryModeEnum mode);
141

142
    void historySizeChanged(int);
143 144 145 146

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

148 149
    void scrollFullPage();
    void scrollHalfPage();
150

151 152 153 154 155 156
    // keyboard page
    void editKeyBinding();
    void newKeyBinding();
    void keyBindingSelected();
    void removeKeyBinding();

157 158
    // mouse page
    void toggleUnderlineLinks(bool);
159
    void toggleOpenLinksByDirectClick(bool);
160
    void toggleCtrlRequiredForDrag(bool);
161
    void toggleDropUrlsAsText(bool);
162
    void toggleCopyTextToClipboard(bool);
163
    void toggleTrimTrailingSpacesInSelectedText(bool);
164 165 166 167 168 169
    void pasteFromX11Selection();
    void pasteFromClipboard();

    void TripleClickModeChanged(int);
    void wordCharactersChanged(const QString&);

170 171 172
    // advanced page
    void toggleBlinkingText(bool);
    void toggleFlowControl(bool);
173
    void togglebidiRendering(bool);
174
    void lineSpacingChanged(int);
175
    void toggleBlinkingCursor(bool);
176
    void toggleEnableUrlHints(bool);
177

178 179 180 181
    void setCursorShape(int);
    void autoCursorColor();
    void customCursorColor();
    void customCursorColorChanged(const QColor&);
182
    void setDefaultCodec(QTextCodec*);
183

184 185 186
    // apply the first previewed changes stored up by delayedPreview()
    void delayedPreviewActivate();

187 188
private:
    // initialize various pages of the dialog
Jekyll Wu's avatar
Jekyll Wu committed
189 190 191 192 193 194
    void setupGeneralPage(const Profile::Ptr profile);
    void setupTabsPage(const Profile::Ptr profile);
    void setupAppearancePage(const Profile::Ptr profile);
    void setupKeyboardPage(const Profile::Ptr profile);
    void setupScrollingPage(const Profile::Ptr profile);
    void setupAdvancedPage(const Profile::Ptr profile);
195
    void setupMousePage(const Profile::Ptr info);
196

197
    void updateColorSchemeList(bool selectCurrentScheme = false);
Robert Knight's avatar
 
Robert Knight committed
198
    void updateColorSchemeButtons();
199
    void updateKeyBindingsList(bool selectCurrentTranslator = false);
Robert Knight's avatar
 
Robert Knight committed
200
    void updateKeyBindingsButtons();
201

202
    void showColorSchemeEditor(bool isNewScheme);
203
    void closeColorSchemeEditor();
204 205
    void showKeyBindingEditor(bool newTranslator);

Robert Knight's avatar
Robert Knight committed
206
    void preview(int property , const QVariant& value);
207
    void delayedPreview(int property , const QVariant& value);
208
    void unpreview(int property);
209
    void unpreviewAll();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
210
    void enableIfNonEmptySelection(QWidget* widget, QItemSelectionModel* selectionModel);
211

212
    void updateCaption(const Profile::Ptr profile);
Robert Knight's avatar
 
Robert Knight committed
213 214
    void updateTransparencyWarning();

215 216 217 218 219
    // 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);

220 221 222 223
    // helper method for creating an empty & hidden profile and assigning
    // it to _tempProfile.
    void createTempProfile();

Jekyll Wu's avatar
Jekyll Wu committed
224
    // Enable or disable apply button, used only within
225 226 227
    // updateTempProfileProperty().
    void updateButtonApply();

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
230 231 232 233
    struct RadioOption {
        QAbstractButton* button;
        int value;
        const char* slot;
Robert Knight's avatar
Robert Knight committed
234
    };
235
    void setupRadio(RadioOption* possibilities, int actual);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
236 237 238 239
    struct BooleanOption {
        QAbstractButton* button;
        Profile::Property property;
        const char* slot;
Robert Knight's avatar
Robert Knight committed
240
    };
241
    void setupCheckBoxes(BooleanOption* options , const Profile::Ptr profile);
242

243
    Ui::EditProfileDialog* _ui;
244
    Profile::Ptr _tempProfile;
245
    Profile::Ptr _profile;
246

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
254
    QHash<int, QVariant> _delayedPreviewProperties;
255
    QTimer* _delayedPreviewTimer;
256 257

    ColorSchemeEditor* _colorDialog;
Laurent Montel's avatar
Laurent Montel committed
258
    QDialogButtonBox *mButtonBox;
259 260 261 262 263 264 265
};

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

268
public:
269
    explicit ColorSchemeViewDelegate(QObject* parent = 0);
270 271 272 273

    // reimplemented
    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;
Kurt Hindenburg's avatar
Kurt Hindenburg committed
274 275
    virtual QSize sizeHint(const QStyleOptionViewItem& option,
                           const QModelIndex& index) const;
276
};
Stephan Binner's avatar
Stephan Binner committed
277
}
278

279
#endif // EDITPROFILEDIALOG_H