EditProfileDialog.h 7.89 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>

33 34 35
// Local
#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
{
43
    class EditProfileDialog;
Stephan Binner's avatar
Stephan Binner committed
44
}
45 46 47 48

namespace Konsole
{

49
class Profile;
50 51

/**
52
 * A dialog which allows the user to edit a profile.
53 54 55 56 57 58 59 60 61 62
 * 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.
63
 */
64
class KONSOLEPRIVATE_EXPORT EditProfileDialog : public KDialog
65 66 67 68 69
{
Q_OBJECT

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

    /**
     * Initialises the dialog with the settings for the specified session
     * type.
     *
77 78 79
     * When the dialog closes, the profile will be updated in the SessionManager
     * with the altered settings.
     *
80
     * @param profile The profile to be edited
81
     */
82
    void setProfile(Profile::Ptr profile);
83

Robert Knight's avatar
 
Robert Knight committed
84 85 86 87 88 89 90 91
    /** 
     * 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();

92
public slots:
93
    // reimplemented
94
    virtual void accept();
95
    // reimplemented 
96
    virtual void reject();
97

98 99 100
protected:
    virtual bool eventFilter(QObject* watched , QEvent* event);

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

105 106 107
    // saves changes to profile
    void save();

108 109
    // general page
    void selectInitialDir();
110 111 112 113
    void selectIcon();

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

119 120
    void insertTabTitleText(const QString& text);
    void insertRemoteTabTitleText(const QString& text);
121

122
    void showMenuBar(bool);
123
    void showEnvironmentEditor();
124 125
    void tabBarVisibilityChanged(int);
    void tabBarPositionChanged(int);
126
    void showNewTabButton(bool);
127

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

139 140
    void colorSchemeAnimationUpdate();

141 142 143 144 145 146 147 148 149 150 151
    // scrolling page
    void noScrollBack();
    void fixedScrollBack();
    void unlimitedScrollBack();
   
    void scrollBackLinesChanged(int);

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

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

158 159 160 161
    // advanced page
    void toggleBlinkingText(bool);
    void toggleFlowControl(bool);
    void toggleResizeWindow(bool);
162
    void togglebidiRendering(bool);
163
    void toggleBlinkingCursor(bool);
164
    void toggleTripleClickMode(bool);
165

166 167 168 169 170
    void setCursorShape(int);
    void autoCursorColor();
    void customCursorColor();
    void customCursorColorChanged(const QColor&);
    void wordCharactersChanged(const QString&);
171
    void setDefaultCodec(QTextCodec*);
172

173 174 175
    // apply the first previewed changes stored up by delayedPreview()
    void delayedPreviewActivate();

176 177
private:
    // initialize various pages of the dialog
178 179 180 181 182 183
    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);
184

185
    void updateColorSchemeList(bool selectCurrentScheme = false);
Robert Knight's avatar
 
Robert Knight committed
186
    void updateColorSchemeButtons();
187
    void updateKeyBindingsList(bool selectCurrentTranslator = false);
Robert Knight's avatar
 
Robert Knight committed
188
    void updateKeyBindingsButtons();
189

190
    void showColorSchemeEditor(bool newScheme);
191 192 193
    void showKeyBindingEditor(bool newTranslator);

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

Robert Knight's avatar
Robert Knight committed
195
    void preview(int property , const QVariant& value);
196
    void delayedPreview(int property , const QVariant& value);
197
    void unpreview(int property);
198
    void unpreviewAll();
Robert Knight's avatar
 
Robert Knight committed
199
    void enableIfNonEmptySelection(QWidget* widget,QItemSelectionModel* selectionModel);
200

201
    void updateCaption(const Profile::Ptr profile);
Robert Knight's avatar
 
Robert Knight committed
202 203
    void updateTransparencyWarning();

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

Robert Knight's avatar
Robert Knight committed
206 207 208 209
    struct RadioOption
    {
       QAbstractButton* button;
       int property;
Rolf Eike Beer's avatar
Rolf Eike Beer committed
210
       const char* slot; 
Robert Knight's avatar
Robert Knight committed
211 212 213 214 215 216
    };
    void setupRadio(RadioOption* possible,int actual);
    struct ComboOption
    {
       QAbstractButton* button;
       int property;
Rolf Eike Beer's avatar
Rolf Eike Beer committed
217
       const char* slot;
Robert Knight's avatar
Robert Knight committed
218
    };
219
    void setupCombo(ComboOption* options , const Profile::Ptr profile);
220

221
    const Profile::Ptr lookupProfile() const;
222

223
    Ui::EditProfileDialog* _ui;
224
    Profile::Ptr _tempProfile;
225
    Profile::Ptr _profile;
226

227 228 229 230 231
    // 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;
232
    QHash<int,QVariant> _previewedProperties;
233
    
Robert Knight's avatar
 
Robert Knight committed
234
    QTimeLine* _colorSchemeAnimationTimeLine;
235 236 237

    QHash<int,QVariant> _delayedPreviewProperties;
    QTimer* _delayedPreviewTimer;
238 239 240 241 242 243 244
};

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

247 248 249 250 251 252 253 254 255
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;

256 257 258 259 260 261 262 263 264 265 266 267 268
    /** 
     * 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;

269 270
};

Stephan Binner's avatar
Stephan Binner committed
271
}
272

273
#endif // EDITPROFILEDIALOG_H