1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
// Created on: 2017-06-16
// Created by: Natalia ERMOLAEVA
// Copyright (c) 2017 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <inspector/DFBrowser_SearchLine.hxx>
#include <inspector/DFBrowser_SearchLineModel.hxx>
#include <inspector/DFBrowser_Window.hxx>
#include <inspector/DFBrowserPane_Tools.hxx>
#include <inspector/DFBrowser_Module.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
#include <Standard_WarningsDisable.hxx>
#include <QStringList>
#include <QWidget>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QToolButton>
#include <QCompleter>
#include <QIcon>
#include <QPaintEvent>
#include <QPainter>
#include <QStyle>
#include <Standard_WarningsRestore.hxx>
//! class DFBrowser_LineEdit
//! Extension of Qt line edit to visualize help text until the line edit control has not been filled
//! yet
class DFBrowser_LineEdit : public QLineEdit
{
public:
//! Constructor
DFBrowser_LineEdit(QWidget* theParent)
: QLineEdit(theParent)
{
}
//! Destructor
virtual ~DFBrowser_LineEdit() {}
//! Sets text that is shown in line edit it the text of this control is empty
//! \param theText a string value
void setPlaneHolder(const QString& theText) { myPlaceHolder = theText; }
//! Draws the line edit context, put plane holder if text is empty
//! \param theEvent a paint event
virtual void paintEvent(QPaintEvent* theEvent) Standard_OVERRIDE
{
QLineEdit::paintEvent(theEvent);
if (!text().isEmpty())
return;
QPainter aPainter(this);
QFontMetrics aFontMetrics = fontMetrics();
QRect aLineRect = rect();
Qt::Alignment anAlignment = QStyle::visualAlignment(layoutDirection(), Qt::AlignLeft);
QColor aColor = Qt::gray;
QPen anOldpen = aPainter.pen();
aPainter.setPen(aColor);
aLineRect.adjust(4, 4, 0, 0);
QString anElidedText =
aFontMetrics.elidedText(myPlaceHolder, Qt::ElideRight, aLineRect.width());
aPainter.drawText(aLineRect, anAlignment, anElidedText);
aPainter.setPen(anOldpen);
}
private:
QString myPlaceHolder; //!< text of filling line edit content if the text is empty
};
// =======================================================================
// function : Constructor
// purpose :
// =======================================================================
DFBrowser_SearchLine::DFBrowser_SearchLine(QWidget* theParent)
: QFrame(theParent)
{
QHBoxLayout* aLayout = new QHBoxLayout(this);
aLayout->setContentsMargins(0, 0, 0, 0);
aLayout->setSpacing(0);
myLineControl = new DFBrowser_LineEdit(this);
((DFBrowser_LineEdit*)myLineControl)->setPlaneHolder(QString(tr("Scanning application ...")));
mySearchButton = new QToolButton(this);
mySearchButton->setIcon(QIcon(":/icons/search.png"));
QCompleter* aCompleter = new QCompleter(this);
aCompleter->setCaseSensitivity(Qt::CaseInsensitive);
myLineControl->setCompleter(aCompleter);
aLayout->addWidget(myLineControl);
aLayout->addWidget(mySearchButton);
connect(myLineControl,
SIGNAL(textChanged(const QString&)),
this,
SLOT(onTextChanged(const QString&)));
connect(myLineControl, SIGNAL(returnPressed()), this, SLOT(onReturnPressed()));
connect(mySearchButton, SIGNAL(clicked()), this, SLOT(onSearchButtonClicked()));
ViewControl_Tools::SetWhiteBackground(this);
}
// =======================================================================
// function : SetModule
// purpose :
// =======================================================================
void DFBrowser_SearchLine::SetModule(DFBrowser_Module* theModule)
{
DFBrowser_SearchLineModel* aModel = new DFBrowser_SearchLineModel(myLineControl, theModule);
myLineControl->completer()->setModel(aModel);
}
// =======================================================================
// function : GetModule
// purpose :
// =======================================================================
DFBrowser_Module* DFBrowser_SearchLine::GetModule()
{
DFBrowser_SearchLineModel* aModel = dynamic_cast<DFBrowser_SearchLineModel*>(GetModel());
return aModel->GetModule();
}
// =======================================================================
// function : SetValues
// purpose :
// =======================================================================
void DFBrowser_SearchLine::SetValues(
const QMap<int, QMap<QString, DFBrowser_SearchItemInfo>>& theDocumentValues,
const QMap<int, QStringList>& theDocumentInfoValues)
{
DFBrowser_SearchLineModel* aModel = dynamic_cast<DFBrowser_SearchLineModel*>(GetModel());
aModel->SetValues(theDocumentValues, theDocumentInfoValues);
QString aFirstValue =
!theDocumentInfoValues.empty() ? theDocumentInfoValues.begin().value().first() : "";
DFBrowser_LineEdit* aLineEdit = dynamic_cast<DFBrowser_LineEdit*>(myLineControl);
aLineEdit->setPlaneHolder(QString(tr("Search : %1")).arg(aFirstValue));
}
// =======================================================================
// function : ClearValues
// purpose :
// =======================================================================
void DFBrowser_SearchLine::ClearValues()
{
DFBrowser_SearchLineModel* aModel = dynamic_cast<DFBrowser_SearchLineModel*>(GetModel());
aModel->ClearValues();
DFBrowser_LineEdit* aLineEdit = dynamic_cast<DFBrowser_LineEdit*>(myLineControl);
aLineEdit->setPlaneHolder(QString(tr("Scanning application ...")));
}
// =======================================================================
// function : onTextChanged
// purpose :
// =======================================================================
void DFBrowser_SearchLine::onTextChanged(const QString& theText)
{
mySearchButton->setIcon(theText.isEmpty() ? QIcon(":/icons/search.png")
: QIcon(":/icons/search_cancel.png"));
emit searchActivated();
}
// =======================================================================
// function : onSearchButtonClicked
// purpose :
// =======================================================================
void DFBrowser_SearchLine::onSearchButtonClicked()
{
if (!Text().isEmpty())
SetText(QString());
}
|