1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Designer of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include "lineedit_taskmenu.h"
30#include "inplace_editor.h"
31
32#include <QtDesigner/abstractformwindow.h>
33
34#include <QtWidgets/qaction.h>
35#include <QtWidgets/qstyle.h>
36#include <QtWidgets/qstyleoption.h>
37
38QT_BEGIN_NAMESPACE
39
40namespace qdesigner_internal {
41
42// -------- LineEditTaskMenuInlineEditor
43class LineEditTaskMenuInlineEditor : public TaskMenuInlineEditor
44{
45public:
46 LineEditTaskMenuInlineEditor(QLineEdit *button, QObject *parent);
47
48protected:
49 QRect editRectangle() const override;
50};
51
52LineEditTaskMenuInlineEditor::LineEditTaskMenuInlineEditor(QLineEdit *w, QObject *parent) :
53 TaskMenuInlineEditor(w, ValidationSingleLine, QStringLiteral("text"), parent)
54{
55}
56
57QRect LineEditTaskMenuInlineEditor::editRectangle() const
58{
59 QStyleOption opt;
60 opt.init(w: widget());
61 return opt.rect;
62}
63
64// --------------- LineEditTaskMenu
65LineEditTaskMenu::LineEditTaskMenu(QLineEdit *lineEdit, QObject *parent) :
66 QDesignerTaskMenu(lineEdit, parent),
67 m_editTextAction(new QAction(tr(s: "Change text..."), this))
68{
69 TaskMenuInlineEditor *editor = new LineEditTaskMenuInlineEditor(lineEdit, this);
70 connect(sender: m_editTextAction, signal: &QAction::triggered, receiver: editor, slot: &LineEditTaskMenuInlineEditor::editText);
71 m_taskActions.append(t: m_editTextAction);
72
73 QAction *sep = new QAction(this);
74 sep->setSeparator(true);
75 m_taskActions.append(t: sep);
76}
77
78QAction *LineEditTaskMenu::preferredEditAction() const
79{
80 return m_editTextAction;
81}
82
83QList<QAction*> LineEditTaskMenu::taskActions() const
84{
85 return m_taskActions + QDesignerTaskMenu::taskActions();
86}
87
88}
89
90QT_END_NAMESPACE
91

source code of qttools/src/designer/src/components/taskmenu/lineedit_taskmenu.cpp