File indexing completed on 2024-04-14 04:53:07

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2001 Carsten Pfeiffer <pfeiffer@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KONQ_COMBO_H
0008 #define KONQ_COMBO_H
0009 
0010 #include <khistorycombobox.h>
0011 
0012 class QEvent;
0013 class QKeyEvent;
0014 class QPixmap;
0015 class KCompletion;
0016 class KConfig;
0017 
0018 // we use KHistoryCombo _only_ for the up/down keyboard handling, otherwise
0019 // KComboBox would do fine.
0020 class KonqCombo : public KHistoryComboBox
0021 {
0022     Q_OBJECT
0023 
0024 public:
0025     explicit KonqCombo(QWidget *parent);
0026     ~KonqCombo() override;
0027 
0028     // initializes with the completion object and calls loadItems()
0029     void init(KCompletion *);
0030 
0031     // determines internally if it's temporary or final
0032     void setURL(const QString &url);
0033 
0034     void setTemporary(const QString &);
0035     void setTemporary(const QString &, const QPixmap &);
0036     void clearTemporary(bool makeCurrent = true);
0037     void removeURL(const QString &url);
0038 
0039     void insertPermanent(const QString &);
0040 
0041     void updatePixmaps();
0042 
0043     void loadItems();
0044     void saveItems();
0045 
0046     static void setConfig(KConfig *);
0047 
0048     virtual void popup();
0049 
0050     void setPageSecurity(int);
0051 
0052     void insertItem(const QString &text, int index = -1, const QString &title = QString());
0053     void insertItem(const QPixmap &pixmap, const QString &text, int index = -1, const QString &title = QString());
0054 
0055 protected:
0056     void keyPressEvent(QKeyEvent *) override;
0057     bool eventFilter(QObject *, QEvent *) override;
0058     void mousePressEvent(QMouseEvent *) override;
0059     void mouseMoveEvent(QMouseEvent *) override;
0060     void paintEvent(QPaintEvent *) override;
0061     void selectWord(QKeyEvent *e);
0062 
0063 Q_SIGNALS:
0064     /**
0065       Specialized signal that emits the state of the modifier
0066       keys along with the actual activated text.
0067      */
0068     void activated(const QString &, Qt::KeyboardModifiers);
0069 
0070     /**
0071       User has clicked on the security lock in the combobar
0072      */
0073     void showPageSecurity();
0074 
0075 private Q_SLOTS:
0076     void slotCleared();
0077     void slotSetIcon(int index);
0078     void slotActivated(const QString &text);
0079     void slotTextEdited(const QString &text);
0080     void slotReturnPressed();
0081     void slotCompletionModeChanged(KCompletion::CompletionMode);
0082 
0083 private:
0084     void updateItem(const QPixmap &pix, const QString &, int index, const QString &title);
0085     void saveState();
0086     void restoreState();
0087     void applyPermanent();
0088     QString temporaryItem() const
0089     {
0090         return itemText(temporary);
0091     }
0092     void removeDuplicates(int index);
0093 
0094     bool m_returnPressed;
0095     bool m_permanent;
0096     int m_cursorPos;
0097     int m_currentIndex;
0098     QString m_currentText;
0099     QString m_selectedText;
0100     QPoint m_dragStart;
0101     int m_pageSecurity;
0102 
0103     void getStyleOption(QStyleOptionComboBox *combo);
0104 
0105     static KConfig *s_config;
0106     static const int temporary; // the index of our temporary item
0107 };
0108 
0109 #endif // KONQ_COMBO_H