| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2015 Eivind Kvedalen <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 51 Franklin Street, * |
| 19 |
* Fifth Floor, Boston, MA 02110-1301, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef QUANTITYSPINBOX_P_H |
| 24 |
#define QUANTITYSPINBOX_P_H |
| 25 |
|
| 26 |
#include <QLabel> |
| 27 |
#include <QMouseEvent> |
| 28 |
#include <QLineEdit> |
| 29 |
|
| 30 |
class ExpressionLabel: public QLabel |
| 31 |
{ |
| 32 |
Q_OBJECT |
| 33 |
public: |
| 34 |
ExpressionLabel(QWidget* parent) |
| 35 |
: QLabel(parent) |
| 36 |
{} |
| 37 |
|
| 38 |
void setExpressionText(const QString& text) |
| 39 |
{ |
| 40 |
if (text.isEmpty()) { |
| 41 |
this->setToolTip(genericExpressionEditorTooltip); |
| 42 |
} |
| 43 |
else { |
| 44 |
this->setToolTip(expressionEditorTooltipPrefix + text); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
void show() |
| 49 |
{ |
| 50 |
if (auto parentLineEdit = qobject_cast<QLineEdit*>(parent())) { |
| 51 |
// horizontal margin, so text will not be behind the icon |
| 52 |
QMargins margins = parentLineEdit->contentsMargins(); |
| 53 |
margins.setRight(2 * margins.right() + sizeHint().width()); |
| 54 |
parentLineEdit->setContentsMargins(margins); |
| 55 |
} |
| 56 |
QLabel::show(); |
| 57 |
} |
| 58 |
|
| 59 |
protected: |
| 60 |
void mouseReleaseEvent(QMouseEvent* event) override |
| 61 |
{ |
| 62 |
if (rect().contains(event->pos())) { |
| 63 |
Q_EMIT clicked(); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
Q_SIGNALS: |
| 68 |
void clicked(); |
| 69 |
|
| 70 |
private: |
| 71 |
const QString genericExpressionEditorTooltip = tr("Enter expression… (=)"); |
| 72 |
const QString expressionEditorTooltipPrefix = tr("Expression:") + QStringLiteral(" "); |
| 73 |
}; |
| 74 |
|
| 75 |
#endif // QUANTITYSPINBOX_P_H |