EditProfileDialog.h 7.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
    Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>

    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>

33
class QAbstractButton;
Robert Knight's avatar
 
Robert Knight committed
34
class QItemSelectionModel;
35
class QTextCodec;
36
class QTimeLine;
37

38 39
namespace Ui
{
40
    class EditProfileDialog;
Stephan Binner's avatar
Stephan Binner committed
41
}
42 43 44 45

namespace Konsole
{

46
class Profile;
47 48

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

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

    /**
     * Initialises the dialog with the settings for the specified session
     * type.
     *
74 75 76
     * When the dialog closes, the profile will be updated in the SessionManager
     * with the altered settings.
     *
77 78
     * @param key The key for the session type provided by the SessionManager instance
     */
79
    void setProfile(const QString& key);
80

Robert Knight's avatar
 
Robert Knight committed
81 82 83 84 85 86 87 88
    /** 
     * Selects the text in the profile name edit area. 
     * 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();
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 111 112 113
    void selectIcon();

    void profileNameChanged(const QString& text);
    void initialDirChanged(const QString& text);
    void commandChanged(const QString& text);
    void tabTitleFormatChanged(const QString& text);
    void remoteTabTitleFormatChanged(const QString& text);
114

115 116
    void insertTabTitleText(const QString& text);
    void insertRemoteTabTitleText(const QString& text);
117

118
    void showMenuBar(bool);
119
    void showEnvironmentEditor();
120 121
    void tabBarVisibilityChanged(int);
    void tabBarPositionChanged(int);
122

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

134 135
    void colorSchemeAnimationUpdate();

136 137 138 139 140 141 142 143 144 145 146
    // scrolling page
    void noScrollBack();
    void fixedScrollBack();
    void unlimitedScrollBack();
   
    void scrollBackLinesChanged(int);

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

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

153 154 155 156
    // advanced page
    void toggleBlinkingText(bool);
    void toggleFlowControl(bool);
    void toggleResizeWindow(bool);
157
    void toggleBlinkingCursor(bool);
158

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

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

169 170
private:
    // initialize various pages of the dialog
171
    void setupGeneralPage(const Profile* info);
172
    void setupTabsPage(const Profile* info);
173
    void setupAppearancePage(const Profile* info);
174 175 176
    void setupKeyboardPage(const Profile* info);
    void setupScrollingPage(const Profile* info);
    void setupAdvancedPage(const Profile* info);
177

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

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

    void changeCheckedItem( QAbstractItemModel* mode,  const QModelIndex& to );
187

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

Robert Knight's avatar
 
Robert Knight committed
194
    void updateCaption(const QString& profileName);
Robert Knight's avatar
 
Robert Knight committed
195 196
    void updateTransparencyWarning();

Robert Knight's avatar
Robert Knight committed
197 198 199 200
    struct RadioOption
    {
       QAbstractButton* button;
       int property;
Rolf Eike Beer's avatar
Rolf Eike Beer committed
201
       const char* slot; 
Robert Knight's avatar
Robert Knight committed
202 203 204 205 206 207
    };
    void setupRadio(RadioOption* possible,int actual);
    struct ComboOption
    {
       QAbstractButton* button;
       int property;
Rolf Eike Beer's avatar
Rolf Eike Beer committed
208
       const char* slot;
Robert Knight's avatar
Robert Knight committed
209 210
    };
    void setupCombo(ComboOption* options , const Profile* profile);
211

212 213
    const Profile* lookupProfile() const;

214
    Ui::EditProfileDialog* _ui;
215
    Profile* _tempProfile;
216
    QString _profileKey;
217

218 219 220 221 222
    // keeps track of pages which need to be updated to match the current
    // profile.  all elements in this vector are set to true when the 
    // profile is changed and individual elements are set to false 
    // after an update by a call to ensurePageLoaded()
    QVector<bool> _pageNeedsUpdate;
223
    QHash<int,QVariant> _previewedProperties;
224
    
Robert Knight's avatar
 
Robert Knight committed
225
    QTimeLine* _colorSchemeAnimationTimeLine;
226 227 228

    QHash<int,QVariant> _delayedPreviewProperties;
    QTimer* _delayedPreviewTimer;
229 230 231 232 233 234 235
};

/**
 * A delegate which can display and edit color schemes in a view.
 */
class ColorSchemeViewDelegate : public QAbstractItemDelegate
{
236 237
Q_OBJECT

238 239 240 241 242 243 244 245 246
public:
    ColorSchemeViewDelegate(QObject* parent = 0);

    // reimplemented
    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;
    virtual QSize sizeHint( const QStyleOptionViewItem& option,
                       const QModelIndex& index) const;

247 248 249 250 251 252 253 254 255 256 257 258 259
    /** 
     * 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
     * determine how to render the item ( with 0 being the beginning 
     * of the animation and 1.0 being the end )
     */
    void setEntryTimeLine( QTimeLine* timeLine );

private:
    QPointer<QTimeLine> _entryTimeLine;

260 261
};

Stephan Binner's avatar
Stephan Binner committed
262
}
263

264
#endif // EDITPROFILEDIALOG_H