Falkon Develop
Cross-platform Qt-based web browser
lineedit.h
Go to the documentation of this file.
1#ifndef LINEEDIT_H
2#define LINEEDIT_H
3
31/* ============================================================
32* Falkon - Qt web browser
33* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
34*
35* This program is free software: you can redistribute it and/or modify
36* it under the terms of the GNU General Public License as published by
37* the Free Software Foundation, either version 3 of the License, or
38* (at your option) any later version.
39*
40* This program is distributed in the hope that it will be useful,
41* but WITHOUT ANY WARRANTY; without even the implied warranty of
42* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43* GNU General Public License for more details.
44*
45* You should have received a copy of the GNU General Public License
46* along with this program. If not, see <http://www.gnu.org/licenses/>.
47* ============================================================ */
48
49#include <QLineEdit>
50#include <QTextLayout>
51#include "qzcommon.h"
52
53class QHBoxLayout;
54
55/*
56LineEdit is a subclass of QLineEdit that provides an easy and simple
57way to add widgets on the left or right hand side of the text.
58
59The layout of the widgets on either side are handled by a QHBoxLayout.
60You can set the spacing around the widgets with setWidgetSpacing().
61
62As widgets are added to the class they are inserted from the outside
63into the center of the widget.
64*/
65class SideWidget;
66class FALKON_EXPORT LineEdit : public QLineEdit
67{
68 Q_OBJECT
69 Q_PROPERTY(QSize fixedsize READ size WRITE setFixedSize)
70 Q_PROPERTY(int leftMargin READ leftMargin WRITE setLeftMargin)
71 Q_PROPERTY(int fixedwidth READ width WRITE setFixedWidth)
72 Q_PROPERTY(int fixedheight READ height WRITE setFixedHeight)
73 Q_PROPERTY(int minHeight READ minHeight WRITE setMinHeight)
74
75public:
76 using TextFormat = QList<QTextLayout::FormatRange>;
77
80 RightSide
81 };
82
84 Undo = 0,
85 Redo = 1,
86 Cut = 2,
87 Copy = 3,
88 Paste = 4,
89 PasteAndGo = 5,
90 Delete = 6,
91 ClearAll = 7,
92 SelectAll = 8
93 };
94
95 LineEdit(QWidget* parent = nullptr);
96
97 void addWidget(QWidget* widget, WidgetPosition position);
98 void removeWidget(QWidget* widget);
99 void setWidgetSpacing(int spacing);
100 int widgetSpacing() const;
101 int leftMargin() const;
102
103 void setTextFormat(const TextFormat &format);
104 void clearTextFormat();
105
106 int minHeight() const;
107 void setMinHeight(int height);
108
109 QSize sizeHint() const override;
110 QAction* editAction(EditAction action) const;
111
112public Q_SLOTS:
113 void setLeftMargin(int margin);
114 void updateTextMargins();
115
116protected:
117 void focusInEvent(QFocusEvent* event) override;
118 void mousePressEvent(QMouseEvent* event) override;
119 void mouseReleaseEvent(QMouseEvent* event) override;
120 void mouseDoubleClickEvent(QMouseEvent* event) override;
121 void resizeEvent(QResizeEvent *event) override;
122 bool event(QEvent* event) override;
123
124 QMenu* createContextMenu();
125
126private Q_SLOTS:
127 void updateActions();
128 void updatePasteActions();
129 void slotDelete();
130
131private:
132 void init();
133
134 SideWidget* m_leftWidget;
135 SideWidget* m_rightWidget;
136 QHBoxLayout* m_leftLayout;
137 QHBoxLayout* m_rightLayout;
138 QHBoxLayout* mainLayout;
139 QAction* m_editActions[9];
140
141 int m_minHeight;
142 int m_leftMargin;
143 bool m_ignoreMousePress;
144};
145
146
147class FALKON_EXPORT SideWidget : public QWidget
148{
149 Q_OBJECT
150
151Q_SIGNALS:
153
154public:
155 SideWidget(QWidget* parent = nullptr);
156
157protected:
158 bool event(QEvent* event) override;
159
160};
161
162#endif // LINEEDIT_H
WidgetPosition
Definition: lineedit.h:78
@ LeftSide
Definition: lineedit.h:79
EditAction
Definition: lineedit.h:83
QList< QTextLayout::FormatRange > TextFormat
Definition: lineedit.h:76
void sizeHintChanged()
#define FALKON_EXPORT
Definition: qzcommon.h:28