File indexing completed on 2025-03-09 03:57:08

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-05-22
0007  * Description : a control widget for the AdvancedRename utility
0008  *
0009  * SPDX-FileCopyrightText: 2009-2012 by Andi Clemens <andi dot clemens at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #ifndef DIGIKAM_ADVANCED_RENAME_WIDGET_H
0016 #define DIGIKAM_ADVANCED_RENAME_WIDGET_H
0017 
0018 // Qt includes
0019 
0020 #include <QString>
0021 #include <QWidget>
0022 
0023 // Local includes
0024 
0025 #include "rule.h"
0026 #include "digikam_export.h"
0027 
0028 class QMenu;
0029 
0030 namespace Digikam
0031 {
0032 
0033 class ParseSettings;
0034 class Parser;
0035 
0036 class DIGIKAM_GUI_EXPORT AdvancedRenameWidget : public QWidget
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041 
0042     enum LayoutStyle
0043     {
0044         LayoutNormal,
0045         LayoutCompact
0046     };
0047 
0048     enum ControlWidget
0049     {
0050         None               = 0x0,
0051         ToolTipButton      = 0x1,
0052         TokenButtons       = 0x2,
0053         ModifierToolButton = 0x4,
0054         DefaultControls    = TokenButtons | ToolTipButton | ModifierToolButton
0055     };
0056     Q_DECLARE_FLAGS(ControlWidgets, ControlWidget)
0057 
0058 public:
0059 
0060     explicit AdvancedRenameWidget(QWidget* const parent = nullptr);
0061     ~AdvancedRenameWidget() override;
0062 
0063     /**
0064      * returns the current parse string
0065      */
0066     QString parseString() const;
0067 
0068     /**
0069      *
0070      * sets the current parse string
0071      * @param text the new parse string
0072      */
0073     void    setParseString(const QString& text);
0074 
0075     void setParseTimerDuration(int milliseconds);
0076 
0077     /**
0078      * resets the current parse string, the LineEdit widget will be empty
0079      */
0080     void    clearParseString();
0081 
0082     /**
0083      * clears the parse string as well as the history
0084      */
0085     void    clear();
0086 
0087     /**
0088      * sets the current parser. If a parser has already been assigned, it will
0089      * be deleted first.
0090      * @param parser a pointer to the new parser instance
0091      */
0092     void    setParser(Parser* parser);
0093 
0094     /**
0095      * returns a pointer to the currently assigned parser
0096      */
0097     Parser* parser() const;
0098 
0099     /**
0100      * evaluates the parse string and executes the parser
0101      * @param settings information about the file to be renamed
0102      * @return the new name of the file
0103      */
0104     QString parse(ParseSettings& settings) const;
0105 
0106     /**
0107      * sets the layout of the control widgets
0108      * @see ControlWidget
0109      * @param mask a bitmask for setting the control widgets
0110      */
0111     void setControlWidgets(ControlWidgets mask);
0112 
0113     /**
0114      * set the layout style of the widget
0115      * @param style the style of the layout
0116      * @see LayoutStyle
0117      */
0118     void setLayoutStyle(LayoutStyle style);
0119 
0120     /**
0121      * set focus for the LineEdit widget
0122      */
0123     void focusLineEdit();
0124 
0125     /**
0126      * highlight the LineEdit widgets text
0127      */
0128     void highlightLineEdit();
0129 
0130     /**
0131      * highlight a word in the LineEdit widgets text
0132      */
0133     void highlightLineEdit(const QString& word);
0134 
0135 Q_SIGNALS:
0136 
0137     void signalTextChanged(const QString&);
0138     void signalReturnPressed();
0139 
0140 private Q_SLOTS:
0141 
0142     void slotToolTipButtonToggled(bool);
0143     void slotTokenMarked(bool);
0144 
0145 private:
0146 
0147     void createToolTip();
0148 
0149     void   registerParserControls();
0150     QMenu* createControlsMenu(QWidget* const parent, const RulesList& rules);
0151 
0152     void calculateLayout();
0153 
0154     void setupWidgets();
0155 
0156     void readSettings();
0157     void writeSettings();
0158 
0159 private:
0160 
0161     // Disable
0162     AdvancedRenameWidget(const AdvancedRenameWidget&)            = delete;
0163     AdvancedRenameWidget& operator=(const AdvancedRenameWidget&) = delete;
0164 
0165 private:
0166 
0167     class Private;
0168     Private* const d;
0169 };
0170 
0171 } // namespace Digikam
0172 
0173 Q_DECLARE_OPERATORS_FOR_FLAGS(Digikam::AdvancedRenameWidget::ControlWidgets)
0174 
0175 #endif // DIGIKAM_ADVANCED_RENAME_WIDGET_H