Esempio n. 1
0
void WizTitleEdit::onTitleEditingFinished()
{
    setCursorPosition(0);
    //
    WIZDOCUMENTDATA data;
    WizDatabase& db = WizDatabaseManager::instance()->db(noteView()->note().strKbGUID);
    if (db.documentFromGuid(noteView()->note().strGUID, data)) {
        if (!db.canEditDocument(data))
            return;

        QString strNewTitle = text().left(255);
        if (strNewTitle.isEmpty() && !placeholderText().isEmpty()) {
            strNewTitle = placeholderText().left(255);
        }
        strNewTitle.replace("\n", " ");
        strNewTitle.replace("\r", " ");
        strNewTitle = strNewTitle.trimmed();
        if (strNewTitle != data.strTitle) {
            data.strTitle = strNewTitle;
            data.tDataModified = WizGetCurrentTime();
            db.modifyDocumentInfo(data);

            emit titleEdited(strNewTitle);
        }
    }
}
Esempio n. 2
0
/** Redefined to display user input like closable "bubbles". */
void TagLineEdit::paintEvent(QPaintEvent *)
{
	QStylePainter p(this);

	// Draw frame
	QStyleOptionFrameV3 frame;
	this->initStyleOption(&frame);
	QPalette palette = QApplication::palette();
	p.setPen(palette.mid().color());
	p.setBrush(palette.base());
	p.drawRect(this->rect().adjusted(0, 0, -1, -1));

	// Compute cursor position
	QRect contentsRect = this->style()->subElementRect(QStyle::SE_LineEditContents, &frame);
	QRect rText = contentsRect.adjusted(2, 0, 0, 0);
	if (!_tags.isEmpty() || (placeholderText().isEmpty() || (!placeholderText().isEmpty() && hasFocus()))) {
		p.setPen(palette.text().color());
		p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, text());

		// Animate cursor is focus is owned by this widget
		bool overlap = false;
		for (TagButton *t : _tags) {
			if (t->frameGeometry().contains(cursorRect().center())) {
				overlap = true;
				break;
			}
		}
		if (!overlap && hasFocus()) {
			this->drawCursor(&p, rText.adjusted(0, 1, 0, -1));
		}
	} else {
		p.setPen(palette.mid().color());
		p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, placeholderText());
	}
}
int ClickLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QLineEdit::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    
#ifndef QT_NO_PROPERTIES
     if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = placeholderText(); break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setPlaceholderText(*reinterpret_cast< QString*>(_v)); break;
        }
        _id -= 1;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 1;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 1;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Esempio n. 4
0
void LineEdit::mousePressEvent(QMouseEvent *event)
{
    //emit selectTextSignal(m_idx);
    //QMessageBox::information(this, "info", QString(tr("textlabel")));
    emit selectedTextSignal(placeholderText());
    //QLabel::mouseDoubleClickEvent(event);
    //QLabel::mousePressEvent(event);
    //QLineEdit::mousePressEvent(event);
}
Esempio n. 5
0
void WInPlaceEdit::setText(const WString& text)
{
  empty_ = text.empty();

  if (!empty_)
    text_->setText(text);
  else
    text_->setText(placeholderText());

  edit_->setText(text);
}
void LibraryFilterLineEdit::paintEvent(QPaintEvent *)
{
	QStylePainter p(this);
	QStyleOptionFrame o;
	initStyleOption(&o);
	o.palette = QApplication::palette();
	//o.rect.adjust(0, 0, -1, 0);

	p.fillRect(rect(), o.palette.base().color());
	QRect rLeft = QRect(o.rect.x(),
						o.rect.y() + 1,
						o.rect.height(),
						o.rect.y() + o.rect.height() - 2);
	QRect rRight = QRect(o.rect.x() + o.rect.width() - o.rect.height(),
						 o.rect.y() + 1,
						 o.rect.height(),
						 o.rect.y() + o.rect.height() - 2);
	QRect rText = QRect(rLeft.x() + rLeft.width(), rLeft.y(), rRight.x(), rRight.y() + rRight.height());
	//rLeft.adjust(0, 1, 0, -1);
	//rRight.adjust(0, 1, 0, -1);

	if (hasFocus()) {
		p.setPen(QPen(o.palette.highlight().color()));
	} else {
		p.setPen(QPen(o.palette.mid().color()));
	}
	p.save();
	p.setRenderHint(QPainter::Antialiasing, true);

	QPainterPath painterPath;
	// 2---1---->   Left curve is painted with 2 calls to cubicTo, starting in 1   <----10--9
	// |   |        First cubic call is with points p1, p2 and p3                       |   |
	// 3   +        Second is with points p3, p4 and p5                                 +   8
	// |   |        With that, a half circle can be filled with linear gradient         |   |
	// 4---5---->                                                                  <----6---7
	painterPath.moveTo(rLeft.x() + rLeft.width(), rLeft.y());
	painterPath.cubicTo(rLeft.x() + rLeft.width(), rLeft.y(),
						rLeft.x() + rLeft.width() / 2.0f, rLeft.y(),
						rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height() / 2.0f);
	painterPath.cubicTo(rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height() / 2.0f,
						rLeft.x() + rLeft.width() / 2.0f, rLeft.y() + rLeft.height(),
						rLeft.x() + rLeft.width(), rLeft.y() + rLeft.height());

	painterPath.lineTo(rRight.x(), rRight.y() + rRight.height());
	painterPath.cubicTo(rRight.x(), rRight.y() + rRight.height(),
						rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height(),
						rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height() / 2.0f);
	painterPath.cubicTo(rRight.x() + rRight.width() / 2.0f, rRight.y() + rRight.height() / 2.0f,
						rRight.x() + rRight.width() / 2.0f, rRight.y(),
						rRight.x(), rRight.y());

	painterPath.closeSubpath();
	p.drawPath(painterPath);

	p.setRenderHint(QPainter::Antialiasing, false);
	p.restore();

	// Paint text and cursor
	if (hasFocus() || !text().isEmpty()) {

		// Highlight selected text
		p.setPen(o.palette.text().color());
		if (hasSelectedText()) {

			QRect rectTextLeft, rectTextMid, rectTextRight;
			QString leftText, midText, rightText;

			int sStart = selectionStart();
			int sEnd = selectedText().length() - 1;

			// Four uses cases to highlight a text
			if (sStart > 0 && sEnd < text().size() - 1) {
				// a[b]cd
				leftText = text().left(sStart);
				midText = selectedText();
				rightText = text().mid(sStart + selectedText().length());

				rectTextLeft.setX(rText.x());
				rectTextLeft.setY(rText.y());
				rectTextLeft.setWidth(fontMetrics().width(leftText));
				rectTextLeft.setHeight(rText.height());

				rectTextMid.setX(rectTextLeft.x() + rectTextLeft.width());
				rectTextMid.setY(rText.y());
				rectTextMid.setWidth(fontMetrics().width(midText));
				rectTextMid.setHeight(rText.height());

				rectTextRight.setX(rectTextMid.x() + rectTextMid.width());
				rectTextRight.setY(rText.y());
				rectTextRight.setWidth(fontMetrics().width(rightText));
				rectTextRight.setHeight(rText.height());

				p.fillRect(rectTextLeft, o.palette.base());
				p.fillRect(rectTextMid, o.palette.highlight());
				p.fillRect(rectTextRight, o.palette.base());

				p.drawText(rectTextLeft, Qt::AlignLeft | Qt::AlignVCenter, leftText);
				p.save();
				p.setPen(o.palette.highlightedText().color());
				p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText);
				p.restore();
				p.drawText(rectTextRight, Qt::AlignLeft | Qt::AlignVCenter, rightText);
			} else if (sStart == 0 && sEnd < text().size() - 1) {
				// [ab]cd
				midText = selectedText();
				rightText = text().mid(sStart + selectedText().length());

				rectTextMid.setX(rText.x());
				rectTextMid.setY(rText.y());
				rectTextMid.setWidth(fontMetrics().width(midText));
				rectTextMid.setHeight(rText.height());

				rectTextRight.setX(rectTextMid.x() + rectTextMid.width());
				rectTextRight.setY(rText.y());
				rectTextRight.setWidth(fontMetrics().width(rightText));
				rectTextRight.setHeight(rText.height());

				p.fillRect(rectTextMid, o.palette.highlight());
				p.fillRect(rectTextRight, o.palette.base());

				p.save();
				p.setPen(o.palette.highlightedText().color());
				p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText);
				p.restore();
				p.drawText(rectTextRight, Qt::AlignLeft | Qt::AlignVCenter, rightText);
			} else if (sStart == 0 && sEnd == text().size() - 1) {
				// [abcd]
				midText = selectedText();

				rectTextMid.setX(rText.x());
				rectTextMid.setY(rText.y());
				rectTextMid.setWidth(fontMetrics().width(midText));
				rectTextMid.setHeight(rText.height());

				p.fillRect(rectTextMid, o.palette.highlight());

				p.save();
				p.setPen(o.palette.highlightedText().color());
				p.drawText(rectTextMid, Qt::AlignLeft | Qt::AlignVCenter, midText);
				p.restore();
			} else {
				// ab[cd]
				// never?
			}
		} else {
			p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, text());
		}
		rText.adjust(0, 2, 0, -2);
		this->drawCursor(&p, rText);
	} else {
		p.setPen(o.palette.mid().color());
		p.drawText(rText, Qt::AlignLeft | Qt::AlignVCenter, placeholderText());
	}
}
Esempio n. 7
0
int QLineEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 21)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 21;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QString*>(_v) = inputMask(); break;
        case 1: *reinterpret_cast< QString*>(_v) = text(); break;
        case 2: *reinterpret_cast< int*>(_v) = maxLength(); break;
        case 3: *reinterpret_cast< bool*>(_v) = hasFrame(); break;
        case 4: *reinterpret_cast< EchoMode*>(_v) = echoMode(); break;
        case 5: *reinterpret_cast< QString*>(_v) = displayText(); break;
        case 6: *reinterpret_cast< int*>(_v) = cursorPosition(); break;
        case 7: *reinterpret_cast< Qt::Alignment*>(_v) = alignment(); break;
        case 8: *reinterpret_cast< bool*>(_v) = isModified(); break;
        case 9: *reinterpret_cast< bool*>(_v) = hasSelectedText(); break;
        case 10: *reinterpret_cast< QString*>(_v) = selectedText(); break;
        case 11: *reinterpret_cast< bool*>(_v) = dragEnabled(); break;
        case 12: *reinterpret_cast< bool*>(_v) = isReadOnly(); break;
        case 13: *reinterpret_cast< bool*>(_v) = isUndoAvailable(); break;
        case 14: *reinterpret_cast< bool*>(_v) = isRedoAvailable(); break;
        case 15: *reinterpret_cast< bool*>(_v) = hasAcceptableInput(); break;
        case 16: *reinterpret_cast< QString*>(_v) = placeholderText(); break;
        case 17: *reinterpret_cast< Qt::CursorMoveStyle*>(_v) = cursorMoveStyle(); break;
        }
        _id -= 18;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setInputMask(*reinterpret_cast< QString*>(_v)); break;
        case 1: setText(*reinterpret_cast< QString*>(_v)); break;
        case 2: setMaxLength(*reinterpret_cast< int*>(_v)); break;
        case 3: setFrame(*reinterpret_cast< bool*>(_v)); break;
        case 4: setEchoMode(*reinterpret_cast< EchoMode*>(_v)); break;
        case 6: setCursorPosition(*reinterpret_cast< int*>(_v)); break;
        case 7: setAlignment(*reinterpret_cast< Qt::Alignment*>(_v)); break;
        case 8: setModified(*reinterpret_cast< bool*>(_v)); break;
        case 11: setDragEnabled(*reinterpret_cast< bool*>(_v)); break;
        case 12: setReadOnly(*reinterpret_cast< bool*>(_v)); break;
        case 16: setPlaceholderText(*reinterpret_cast< QString*>(_v)); break;
        case 17: setCursorMoveStyle(*reinterpret_cast< Qt::CursorMoveStyle*>(_v)); break;
        }
        _id -= 18;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 18;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 18;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 18;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 18;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 18;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 18;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}