Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

EditProfileDialog.h 8.29 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
#include <QtGui/QAbstractItemDelegate>
#include <QtCore/QHash>
26
#include <QtCore/QPointer>
27 28 29 30

// KDE
#include <KDialog>

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

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

40 41
namespace Ui
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
42
class EditProfileDialog;
Stephan Binner's avatar
Stephan Binner committed
43
}
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
 */
61
class KONSOLEPRIVATE_EXPORT EditProfileDialog : public KDialog
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 88
     * 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();

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

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

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

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

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

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

116
    void showTerminalSizeHint(bool);
117
    void saveGeometryOnExit(bool);
118
    void showEnvironmentEditor();
119
    void silenceSecondsChanged(int);
120

121
    // appearance page
122
    void setFontSize(int pointSize);
123 124
    void setFontSliderRange(const QFont&);
    void setFontSliderValue(const QFont&);
125
    void setAntialiasText(bool enable);
126
    void setBoldIntense(bool enable);
127
    void showFontDialog();
128 129 130
    void newColorScheme();
    void editColorScheme();
    void removeColorScheme();
131
    void colorSchemeSelected();
132
    void previewColorScheme(const QModelIndex& index);
133
    void fontSelected(const QFont&);
134

135 136
    void colorSchemeAnimationUpdate();

137
    // scrolling page
138
    void historyModeChanged(Enum::HistoryModeEnum mode);
139

140
    void historySizeChanged(int);
141 142 143 144 145

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

146 147 148 149 150 151
    // keyboard page
    void editKeyBinding();
    void newKeyBinding();
    void keyBindingSelected();
    void removeKeyBinding();

152 153 154
    // advanced page
    void toggleBlinkingText(bool);
    void toggleFlowControl(bool);
155
    void togglebidiRendering(bool);
156
    void toggleBlinkingCursor(bool);
157
    void TripleClickModeChanged(int);
158
    void toggleUnderlineLinks(bool);
159

160 161 162 163 164
    void setCursorShape(int);
    void autoCursorColor();
    void customCursorColor();
    void customCursorColorChanged(const QColor&);
    void wordCharactersChanged(const QString&);
165
    void setDefaultCodec(QTextCodec*);
166

167 168 169
    // apply the first previewed changes stored up by delayedPreview()
    void delayedPreviewActivate();

170 171
private:
    // initialize various pages of the dialog
Jekyll Wu's avatar
Jekyll Wu committed
172 173 174 175 176 177
    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);
178

179
    void updateColorSchemeList(bool selectCurrentScheme = false);
Robert Knight's avatar
 
Robert Knight committed
180
    void updateColorSchemeButtons();
181
    void updateKeyBindingsList(bool selectCurrentTranslator = false);
Robert Knight's avatar
 
Robert Knight committed
182
    void updateKeyBindingsButtons();
183

184
    void showColorSchemeEditor(bool newScheme);
185 186
    void showKeyBindingEditor(bool newTranslator);

Robert Knight's avatar
Robert Knight committed
187
    void preview(int property , const QVariant& value);
188
    void delayedPreview(int property , const QVariant& value);
189
    void unpreview(int property);
190
    void unpreviewAll();
Kurt Hindenburg's avatar
Kurt Hindenburg committed
191
    void enableIfNonEmptySelection(QWidget* widget, QItemSelectionModel* selectionModel);
192

193
    void updateCaption(const Profile::Ptr profile);
Robert Knight's avatar
 
Robert Knight committed
194 195
    void updateTransparencyWarning();

196 197 198 199 200
    // 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);

201 202 203 204
    // helper method for creating an empty & hidden profile and assigning
    // it to _tempProfile.
    void createTempProfile();

Jekyll Wu's avatar
Jekyll Wu committed
205
    // Enable or disable apply button, used only within
206 207 208
    // updateTempProfileProperty().
    void updateButtonApply();

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

Kurt Hindenburg's avatar
Kurt Hindenburg committed
211 212 213 214
    struct RadioOption {
        QAbstractButton* button;
        int value;
        const char* slot;
Robert Knight's avatar
Robert Knight committed
215
    };
216
    void setupRadio(RadioOption* possibilities, int actual);
Kurt Hindenburg's avatar
Kurt Hindenburg committed
217 218 219 220
    struct BooleanOption {
        QAbstractButton* button;
        Profile::Property property;
        const char* slot;
Robert Knight's avatar
Robert Knight committed
221
    };
222
    void setupCheckBoxes(BooleanOption* options , const Profile::Ptr profile);
223

224
    const Profile::Ptr lookupProfile() const;
225

226
    Ui::EditProfileDialog* _ui;
227
    Profile::Ptr _tempProfile;
228
    Profile::Ptr _profile;
229

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

Robert Knight's avatar
 
Robert Knight committed
237
    QTimeLine* _colorSchemeAnimationTimeLine;
238

Kurt Hindenburg's avatar
Kurt Hindenburg committed
239
    QHash<int, QVariant> _delayedPreviewProperties;
240
    QTimer* _delayedPreviewTimer;
241 242 243 244 245 246 247
};

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

250
public:
251
    explicit ColorSchemeViewDelegate(QObject* parent = 0);
252 253 254 255

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

Jekyll Wu's avatar
Jekyll Wu committed
259
    /**
260 261 262 263
     * 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
264
     * determine how to render the item ( with 0 being the beginning
265 266
     * of the animation and 1.0 being the end )
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
267
    void setEntryTimeLine(QTimeLine* timeLine);
268 269 270 271

private:
    QPointer<QTimeLine> _entryTimeLine;

272 273
};

Stephan Binner's avatar
Stephan Binner committed
274
}
275

276
#endif // EDITPROFILEDIALOG_H