Beispiel #1
0
// slot
void WSearchLineEdit::restoreSearch(const QString& text) {
    if(text.isNull()) {
        // disable
        setEnabled(false);
        blockSignals(true);
        setText("- - -");
        blockSignals(false);
        return;
    }
    setEnabled(true);
    qDebug() << "WSearchLineEdit::restoreSearch(" << text << ")";
    blockSignals(true);
    setText(text);
    blockSignals(false);
    if (text == "") {
        m_place = true;
        showPlaceholder();
    } else {
        QPalette pal = palette();
        pal.setColor(foregroundRole(), m_fgc);
        setPalette(pal);
        m_place = false;
    }
    updateCloseButton(text);
}
Beispiel #2
0
void WSearchLineEdit::focusOutEvent(QFocusEvent* event) {
    QLineEdit::focusOutEvent(event);
    if (text().isEmpty()) {
        m_place = true;
        showPlaceholder();
        emit(searchCleared());
    } else {
        m_place = false;
    }
}
WSearchLineEdit::WSearchLineEdit(QWidget* pParent)
        : QLineEdit(pParent),
          WBaseWidget(this) {
    setAcceptDrops(false);
    m_clearButton = new QToolButton(this);
    QPixmap pixmap(":/skins/cross.png");
    m_clearButton->setIcon(QIcon(pixmap));
    m_clearButton->setIconSize(pixmap.size());
    m_clearButton->setCursor(Qt::ArrowCursor);
    m_clearButton->setToolTip(tr("Clear input" , "Clear the search bar input field"));
    m_clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }");
    m_clearButton->hide();

    m_place = true;
    showPlaceholder();

    setFocusPolicy(Qt::ClickFocus);
    QShortcut *setFocusShortcut = new QShortcut(
        QKeySequence(tr("Ctrl+F", "Search|Focus")), this);
    connect(setFocusShortcut, SIGNAL(activated()),
            this, SLOT(setFocus()));

    connect(this, SIGNAL(textChanged(const QString&)),
            this, SLOT(slotTextChanged(const QString&)));

    // Set up a timer to search after a few hundred milliseconds timeout.  This
    // stops us from thrashing the database if you type really fast.
    m_searchTimer.setSingleShot(true);
    connect(&m_searchTimer, SIGNAL(timeout()),
            this, SLOT(triggerSearch()));

    connect(this, SIGNAL(textChanged(const QString&)),
            this, SLOT(slotSetupTimer(const QString&)));

    // When you hit enter, it will trigger the search.
    connect(this, SIGNAL(returnPressed()),
            this, SLOT(triggerSearch()));

    connect(m_clearButton, SIGNAL(clicked()),
            this, SLOT(onSearchTextCleared()));
    // Forces immediate update of tracktable
    connect(m_clearButton, SIGNAL(clicked()),
            this, SLOT(triggerSearch()));

    connect(this, SIGNAL(textChanged(const QString&)),
            this, SLOT(updateCloseButton(const QString&)));

    // The width of the frame for the widget based on the styling.
    int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);

    // Ensures the text does not obscure the clear image.
    setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").
                  arg(m_clearButton->sizeHint().width() + frameWidth + 1));
}
Beispiel #4
0
    void SearchDropdown::addContact()
    {
        const auto mainWindow = Utils::InterConnector::instance().getMainWindow();
        if (mainWindow)
        {
            auto mainPage = mainWindow->getMainPage();
            if (mainPage)
                mainPage->setSearchFocus();
        }

        showPlaceholder();
        searchWidget_->setPlaceholderText(QT_TRANSLATE_NOOP("search_widget", "Phone, UIN, Name, Email"));
    }
InputTextWidget::InputTextWidget(QWidget* parent) :
    QTextEdit(parent)
{
    setMinimumSize(10, 50);
    setContextMenuPolicy(Qt::CustomContextMenu);
    connect(this, &InputTextWidget::customContextMenuRequested, this, &InputTextWidget::showContextMenu);
    showPlaceholder(true);

    actionUndo  = new QAction(QIcon(":/icons/arrow_undo.png"), tr("Undo"), this);
    actionRedo  = new QAction(QIcon(":/icons/arrow_redo.png"), tr("Redo"), this);
    actionCut   = new QAction(QIcon(":/icons/cut.png"), tr("Cut"), this);
    actionCopy  = new QAction(QIcon(":/icons/page_copy.png"), tr("Copy"), this);
    actionPaste = new QAction(QIcon(":/icons/paste_plain.png"), tr("Paste"), this);
    actionUndo->setShortcut(QKeySequence::Undo);
    actionRedo->setShortcut(QKeySequence::Redo);
    actionCut->setShortcut(QKeySequence::Cut);
    actionCopy->setShortcut(QKeySequence::Copy);
    actionPaste->setShortcut(QKeySequence::Paste);
    connect(actionUndo,  &QAction::triggered, this, &InputTextWidget::undo);
    connect(actionRedo,  &QAction::triggered, this, &InputTextWidget::redo);
    connect(actionCut,   &QAction::triggered, this, &InputTextWidget::cutPlainText);
    connect(actionCopy,  &QAction::triggered, this, &InputTextWidget::copyPlainText);
    connect(actionPaste, &QAction::triggered, this, &InputTextWidget::pastePlainText);
}
// FIXME: Replace Placeholder by Qt5.2 placeholder.
void InputTextWidget::focusOutEvent(QFocusEvent *e)
{
    showPlaceholder(true);
    QTextEdit::focusInEvent(e);
}
void InputTextWidget::insertHtml(const QString &text)
{
    showPlaceholder(false);
    QTextEdit::insertHtml(text);
}