File indexing completed on 2024-04-28 05:50:54

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Robert Knight <robertknight@gmail.com>
0003     SPDX-FileCopyrightText: 2018 Harald Sitter <sitter@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef EDITPROFILEDIALOG_H
0009 #define EDITPROFILEDIALOG_H
0010 
0011 #include <QtGlobal>
0012 // KDE
0013 #include <KNSCore/Entry>
0014 #include <KPageDialog>
0015 #include <knewstuff_version.h>
0016 
0017 // Konsole
0018 #include "colorscheme/ColorScheme.h"
0019 #include "colorscheme/ColorSchemeEditor.h"
0020 #include "colorscheme/ColorSchemeViewDelegate.h"
0021 #include "konsoleprivate_export.h"
0022 
0023 #include "profile/Profile.h"
0024 #include "profile/ProfileGroup.h"
0025 
0026 #include "Enumeration.h"
0027 #include "FontDialog.h"
0028 #include "LabelsAligner.h"
0029 #include "keyboardtranslator/KeyboardTranslatorManager.h"
0030 
0031 class KPluralHandlingSpinBox;
0032 class KLocalizedString;
0033 class QItemSelectionModel;
0034 class QTextCodec;
0035 
0036 namespace Ui
0037 {
0038 class EditProfileGeneralPage;
0039 class EditProfileTabsPage;
0040 class EditProfileAppearancePage;
0041 class EditProfileScrollingPage;
0042 class EditProfileKeyboardPage;
0043 class EditProfileMousePage;
0044 class EditProfileAdvancedPage;
0045 }
0046 
0047 namespace Konsole
0048 {
0049 /**
0050  * A dialog which allows the user to edit a profile.
0051  * After the dialog is created, it can be initialized with the settings
0052  * for a profile using setProfile().  When the user makes changes to the
0053  * dialog and accepts the changes, the dialog will update the
0054  * profile in the SessionManager by calling the SessionManager's
0055  * changeProfile() method.
0056  *
0057  * Some changes made in the dialog are preview-only changes which cause
0058  * the SessionManager's changeProfile() method to be called with
0059  * the persistent argument set to false.  These changes are then
0060  * un-done when the dialog is closed.
0061  */
0062 class KONSOLEPRIVATE_EXPORT EditProfileDialog : public KPageDialog
0063 {
0064     Q_OBJECT
0065 
0066 public:
0067     /** Constructs a new dialog with the specified parent. */
0068     explicit EditProfileDialog(QWidget *parent = nullptr);
0069     ~EditProfileDialog() override;
0070 
0071     enum InitialProfileState {
0072         ExistingProfile,
0073         NewProfile,
0074     };
0075 
0076     /**
0077      * Initializes the dialog with the settings for the specified session
0078      * type.
0079      *
0080      * When the dialog closes, the profile will be updated in the SessionManager
0081      * with the altered settings.
0082      *
0083      * @param profile The profile to be edited
0084      * @param state Indicates whether @p profile is an already existing profile
0085      * or a new one being created
0086      */
0087     void setProfile(const Profile::Ptr &profile, InitialProfileState state = EditProfileDialog::ExistingProfile);
0088 
0089     /**
0090      * Selects the text in the profile name edit area.
0091      * When the dialog is being used to create a new profile,
0092      * this can be used to draw the user's attention to the profile name
0093      * and make it easy for them to change it.
0094      */
0095     void selectProfileName();
0096 
0097 public Q_SLOTS:
0098     // reimplemented
0099     void accept() override;
0100     // reimplemented
0101     void reject() override;
0102 
0103 private Q_SLOTS:
0104     QSize sizeHint() const override;
0105 
0106     // sets up the specified tab page if necessary
0107     void preparePage(KPageWidgetItem *current, KPageWidgetItem *before = nullptr);
0108 
0109     // saves changes to profile
0110     void save();
0111 
0112     // general page
0113     void selectInitialDir();
0114     void selectIcon();
0115 
0116     void profileNameChanged(const QString &name);
0117     void initialDirChanged(const QString &dir);
0118     void startInSameDir(bool);
0119     void commandChanged(const QString &command);
0120     void semanticUpDown(bool);
0121     void semanticInputClick(bool enable);
0122 
0123     // tab page
0124     void tabTitleFormatChanged(const QString &format);
0125     void remoteTabTitleFormatChanged(const QString &format);
0126     void tabColorChanged(const QColor &color);
0127     void silenceSecondsChanged(int);
0128 
0129     void terminalColumnsEntryChanged(int);
0130     void terminalRowsEntryChanged(int);
0131     void showTerminalSizeHint(bool);
0132     void setDimWhenInactive(bool);
0133     void setDimValue(int value);
0134     void setBorderWhenActive(bool);
0135     void setFocusBorderColor(const QColor &color);
0136     void showEnvironmentEditor();
0137 
0138     // appearance page
0139     void setAntialiasText(bool enable);
0140     void setBoldIntense(bool enable);
0141     void useFontLineCharacters(bool enable);
0142     void newColorScheme();
0143     void editColorScheme();
0144     void saveColorScheme(const ColorScheme &scheme, bool isNewScheme);
0145     void removeColorScheme();
0146     void setVerticalLine(bool);
0147     void setVerticalLineColumn(int);
0148     // void focusBorderColor();
0149     void focusBorderColorChanged(const QColor &color);
0150     void toggleBlinkingCursor(bool);
0151     void setCursorShape(int);
0152     void autoCursorColor();
0153     void customCursorColor();
0154     void customCursorColorChanged(const QColor &);
0155     void customCursorTextColorChanged(const QColor &);
0156     void terminalMarginChanged(int margin);
0157     void lineSpacingChanged(int);
0158     void setTerminalCenter(bool enable);
0159     void togglebidiRendering(bool);
0160     void togglebidiTableDirOverride(bool);
0161     void togglebidiLineLTR(bool);
0162 
0163     void gotNewColorSchemes(const QList<KNSCore::Entry> &changedEntries);
0164 
0165     /**
0166      * Deletes the selected colorscheme from the user's home dir location
0167      * so that the original one from the system-wide location can be used
0168      * instead
0169      */
0170     void resetColorScheme();
0171 
0172     void colorSchemeSelected();
0173     void previewColorScheme(const QModelIndex &index);
0174     void showFontDialog();
0175     void showEmojiFontDialog();
0176     void toggleMouseWheelZoom(bool enable);
0177 
0178     // scrolling page
0179     void historyModeChanged(Enum::HistoryModeEnum mode);
0180 
0181     void historySizeChanged(int);
0182 
0183     void scrollFullPage();
0184     void scrollHalfPage();
0185     void toggleHighlightScrolledLines(bool enable);
0186     void toggleReflowLines(bool enable);
0187 
0188     // keyboard page
0189     void editKeyBinding();
0190     void newKeyBinding();
0191     void keyBindingSelected();
0192     void removeKeyBinding();
0193     void resetKeyBindings();
0194 
0195     // mouse page
0196     void toggleUnderlineFiles(bool enable);
0197     void toggleUnderlineLinks(bool);
0198     void toggleOpenLinksByDirectClick(bool);
0199     void textEditorCmdEditLineChanged(const QString &text);
0200     void toggleCtrlRequiredForDrag(bool);
0201     void toggleDropUrlsAsText(bool);
0202     void toggleCopyTextToClipboard(bool);
0203     void toggleCopyTextAsHTML(bool);
0204     void toggleTrimLeadingSpacesInSelectedText(bool);
0205     void toggleTrimTrailingSpacesInSelectedText(bool);
0206     void pasteFromX11Selection();
0207     void pasteFromClipboard();
0208     void toggleAlternateScrolling(bool enable);
0209     void toggleAllowColorFilter(bool enable);
0210     void toggleAllowMouseTracking(bool allow);
0211 
0212     void TripleClickModeChanged(int);
0213     void wordCharactersChanged(const QString &);
0214 
0215     // advanced page
0216     void toggleBlinkingText(bool);
0217     void toggleFlowControl(bool);
0218     void updateUrlHintsModifier(bool);
0219     void toggleReverseUrlHints(bool);
0220 
0221     void setDefaultCodec(QTextCodec *);
0222 
0223     void setTextEditorCombo(const Profile::Ptr &profile);
0224 
0225     void toggleAllowLinkEscapeSequence(bool);
0226     void linkEscapeSequenceTextsChanged();
0227 
0228     void peekPrimaryKeySequenceChanged();
0229 
0230     void toggleWordMode(bool mode);
0231     void toggleWordModeAttr(bool mode);
0232     void toggleWordModeAscii(bool mode);
0233     void toggleWordModeBrahmic(bool mode);
0234     void toggleIgnoreWcWidth(bool ignore);
0235 
0236 private:
0237     Q_DISABLE_COPY(EditProfileDialog)
0238 
0239     enum PageID {
0240         GeneralPage = 0,
0241         TabsPage,
0242         AppearancePage,
0243         ScrollingPage,
0244         KeyboardPage,
0245         MousePage,
0246         AdvancedPage,
0247         PagesCount,
0248     };
0249 
0250     // initialize various pages of the dialog
0251     void setupGeneralPage(const Profile::Ptr &profile);
0252     void setupTabsPage(const Profile::Ptr &profile);
0253     void setupAppearancePage(const Profile::Ptr &profile);
0254     void setupKeyboardPage(const Profile::Ptr &profile);
0255     void setupScrollingPage(const Profile::Ptr &profile);
0256     void setupAdvancedPage(const Profile::Ptr &profile);
0257     void setupMousePage(const Profile::Ptr &profile);
0258 
0259     void setMessageGeneralPage(const QString &msg);
0260 
0261     int maxSpinBoxWidth(const KPluralHandlingSpinBox *spinBox, const KLocalizedString &suffix);
0262 
0263     // Returns the name of the colorScheme used in the current profile
0264     const QString currentColorSchemeName() const;
0265 
0266     // select @p selectedColorSchemeName after the changes are saved
0267     // in the colorScheme editor
0268     void updateColorSchemeList(const QString &selectedColorSchemeName = QString());
0269 
0270     void updateColorSchemeButtons();
0271 
0272     // Convenience method
0273     KeyboardTranslatorManager *_keyManager = KeyboardTranslatorManager::instance();
0274 
0275     // Updates the key bindings list widget on the Keyboard tab and selects
0276     // @p selectKeyBindingsName
0277     void updateKeyBindingsList(const QString &selectKeyBindingsName = QString());
0278     void updateKeyBindingsButtons();
0279     void showKeyBindingEditor(bool isNewTranslator);
0280 
0281     void showColorSchemeEditor(bool isNewScheme);
0282     void closeColorSchemeEditor();
0283 
0284     void preview(Profile::Property prop, const QVariant &value);
0285     void unpreview(Profile::Property prop);
0286     void unpreviewAll();
0287     void enableIfNonEmptySelection(QWidget *widget, QItemSelectionModel *selectionModel);
0288 
0289     void updateCaption(const Profile::Ptr &profile);
0290     void updateTransparencyWarning();
0291 
0292     void updateFontPreview(QFont font);
0293     void updateEmojiFontPreview(QFont font);
0294 
0295     // Update _tempProfile in a way of respecting the apply button.
0296     // When used with some previewed property, this method should
0297     // always come after the preview operation.
0298     void updateTempProfileProperty(Profile::Property, const QVariant &value);
0299 
0300     // helper method for clearing all _tempProfile properties and marking it hidden
0301     void resetTempProfile();
0302 
0303     // Enable or disable apply button, used only within
0304     // updateTempProfileProperty() or when toggling the default profile.
0305     void updateButtonApply();
0306 
0307     static QString groupProfileNames(const ProfileGroup::Ptr &group, int maxLength = -1);
0308 
0309     struct ButtonGroupOption {
0310         QAbstractButton *button;
0311         int value;
0312     };
0313     struct ButtonGroupOptions {
0314         QButtonGroup *group;
0315         Profile::Property profileProperty;
0316         bool preview;
0317         QVector<ButtonGroupOption> buttons;
0318     };
0319     void setupButtonGroup(const ButtonGroupOptions &options, const Profile::Ptr &profile);
0320 
0321     // returns false if:
0322     // - the profile name is empty
0323     // - the name matches the name of an already existing profile
0324     // - the existing profile config file is read-only
0325     // otherwise returns true.
0326     bool isProfileNameValid();
0327 
0328     Ui::EditProfileGeneralPage *_generalUi = nullptr;
0329     Ui::EditProfileTabsPage *_tabsUi = nullptr;
0330     Ui::EditProfileAppearancePage *_appearanceUi = nullptr;
0331     Ui::EditProfileScrollingPage *_scrollingUi = nullptr;
0332     Ui::EditProfileKeyboardPage *_keyboardUi = nullptr;
0333     Ui::EditProfileMousePage *_mouseUi = nullptr;
0334     Ui::EditProfileAdvancedPage *_advancedUi = nullptr;
0335 
0336     using PageSetupMethod = void (EditProfileDialog::*)(const Profile::Ptr &);
0337     struct Page {
0338         Page(PageSetupMethod page = nullptr, bool update = false)
0339             : setupPage(page)
0340             , needsUpdate(update)
0341         {
0342         }
0343 
0344         PageSetupMethod setupPage;
0345         bool needsUpdate;
0346     };
0347 
0348     QMap<KPageWidgetItem *, Page> _pages;
0349     KPageWidgetItem *_generalPageItem = nullptr;
0350 
0351     Profile::Ptr _tempProfile;
0352     Profile::Ptr _profile;
0353 
0354     bool _isDefault = false;
0355 
0356     Profile::PropertyMap _previewedProperties;
0357 
0358     ColorSchemeEditor *_colorDialog = nullptr;
0359     QDialogButtonBox *_buttonBox = nullptr;
0360     FontDialog *_fontDialog = nullptr;
0361     FontDialog *_emojiFontDialog = nullptr;
0362 
0363     InitialProfileState _profileState = ExistingProfile;
0364 };
0365 
0366 }
0367 
0368 #endif // EDITPROFILEDIALOG_H