EditProfileDialog.h 6.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
    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.
*/

#ifndef EDITSESSIONDIALOG_H
#define EDITSESSIONDIALOG_H

// 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 29 30 31

// KDE
#include <KDialog>

32
class QAbstractButton;
33
class QTextCodec;
34

35 36
namespace Ui
{
37
    class EditProfileDialog;
Stephan Binner's avatar
Stephan Binner committed
38
}
39 40 41 42

namespace Konsole
{

43
class Profile;
44 45

/**
46
 * A dialog which allows the user to edit a profile.
47 48 49 50 51 52 53 54 55 56
 * 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.
57 58 59
 *
 * TODO: More documentation
 */
60
class EditProfileDialog : public KDialog
61 62 63 64 65
{
Q_OBJECT

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

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

80
public slots:
81
    // reimplemented
82
    virtual void accept();
83
    // reimplemented 
84
    virtual void reject();
85

86 87 88
protected:
    virtual bool eventFilter(QObject* watched , QEvent* event);

89
private slots:
90 91 92
    // sets up the specified tab page if necessary
    void ensurePageLoaded(int);

93 94 95
    // saves changes to profile
    void save();

96 97
    // general page
    void selectInitialDir();
98 99 100 101 102 103 104
    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);
105

106 107
    void insertTabTitleText(const QString& text);
    void insertRemoteTabTitleText(const QString& text);
108

109
    void showMenuBar(bool);
110 111
    void tabBarVisibilityChanged(int);
    void tabBarPositionChanged(int);
112

113
    // appearance page
114 115
    void setFontSize(int pointSize);
    void showFontDialog();
116 117 118
    void newColorScheme();
    void editColorScheme();
    void removeColorScheme();
119
    void colorSchemeSelected();
120
    void previewColorScheme(const QModelIndex& index);
121
    void fontSelected(const QFont&);
122
    //void previewFont(const QFont&);
123

124 125 126 127 128 129 130 131 132 133 134
    // scrolling page
    void noScrollBack();
    void fixedScrollBack();
    void unlimitedScrollBack();
   
    void scrollBackLinesChanged(int);

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

135 136 137 138 139 140
    // keyboard page
    void editKeyBinding();
    void newKeyBinding();
    void keyBindingSelected();
    void removeKeyBinding();

141 142 143 144
    // advanced page
    void toggleBlinkingText(bool);
    void toggleFlowControl(bool);
    void toggleResizeWindow(bool);
145
    void toggleBlinkingCursor(bool);
146

147 148 149 150 151
    void setCursorShape(int);
    void autoCursorColor();
    void customCursorColor();
    void customCursorColorChanged(const QColor&);
    void wordCharactersChanged(const QString&);
152
    void setDefaultCodec(QTextCodec*);
153

154 155
private:
    // initialize various pages of the dialog
156
    void setupGeneralPage(const Profile* info);
157
    void setupAppearancePage(const Profile* info);
158 159 160
    void setupKeyboardPage(const Profile* info);
    void setupScrollingPage(const Profile* info);
    void setupAdvancedPage(const Profile* info);
161

162 163 164
    void updateColorSchemeList();
    void updateKeyBindingsList();

165
    void showColorSchemeEditor(bool newScheme);
166 167 168
    void showKeyBindingEditor(bool newTranslator);

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

Robert Knight's avatar
Robert Knight committed
170
    void preview(int property , const QVariant& value);
171
    void unpreview(int property);
172
    void unpreviewAll();
173

Robert Knight's avatar
Robert Knight committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187
    struct RadioOption
    {
       QAbstractButton* button;
       int property;
       char* slot; 
    };
    void setupRadio(RadioOption* possible,int actual);
    struct ComboOption
    {
       QAbstractButton* button;
       int property;
       char* slot;
    };
    void setupCombo(ComboOption* options , const Profile* profile);
188

189
    Ui::EditProfileDialog* _ui;
190
    Profile* _tempProfile;
191
    QString _profileKey;
192

193
    QVector<bool> _pageInvalidated;
194
    QHash<int,QVariant> _previewedProperties;
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
};

/**
 * A delegate which can display and edit color schemes in a view.
 */
class ColorSchemeViewDelegate : public QAbstractItemDelegate
{
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;

211 212
   // virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, 
   //                               const QModelIndex& index) const;
213 214
   // virtual bool editorEvent(QEvent* event,QAbstractItemModel* model,
   //                          const QStyleOptionViewItem& option, const QModelIndex& index);
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
};

/**
 * A delegate which can display and edit key bindings in a view.
 */
class KeyBindingViewDelegate : public QAbstractItemDelegate
{
public:
    KeyBindingViewDelegate(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;

};

Stephan Binner's avatar
Stephan Binner committed
234
}
235 236
#endif // EDITSESSIONDIALOG_H