예제 #1
0
파일: statusdlg.cpp 프로젝트: AlekSi/Jabbin
//----------------------------------------------------------------------------
// StatusShowDlg
// FIXME: Will no longer be needed once it is out of the groupchat contactview
//----------------------------------------------------------------------------
StatusShowDlg::StatusShowDlg(const UserListItem &u)
	: QDialog(0, 0, false)
{
	setAttribute(Qt::WA_DeleteOnClose);
	// build the dialog
	QVBoxLayout *vb = new QVBoxLayout(this, 8);
	PsiTextView *te = new PsiTextView(this);
	vb->addWidget(te);
	QHBoxLayout *hb = new QHBoxLayout(vb);
	QPushButton *pb = new QPushButton(tr("&Close"), this);
	connect(pb, SIGNAL(clicked()), SLOT(close()));
	hb->addStretch(1);
	hb->addWidget(pb);
	hb->addStretch(1);

	// set the rest up
	te->setReadOnly(true);
	te->setTextFormat(Qt::RichText);
	te->setText(u.makeDesc());

	setWindowTitle(tr("Status for %1").arg(JIDUtil::nickOrJid(u.name(), u.jid().full())));
	resize(400,240);

	pb->setFocus();
}
예제 #2
0
/**
 * Returns HTML markup for selected text. If no text is selected, returns
 * HTML markup for all text.
 */
QString PsiTextView::getHtml() const
{
	PsiTextView *ptv = (PsiTextView *)this;
	QTextCursor cursor = ptv->textCursor();
	int position = ptv->verticalScrollBar()->value();
	
	bool unselectAll = false;
	if (!hasSelectedText()) {
		ptv->selectAll();
		unselectAll = true;
	}
	
	QMimeData *mime = createMimeDataFromSelection();
	QString result = mime->html();
	delete mime;
	
	// we need to restore original position if selectAll() 
	// was called, because setTextCursor() (which is necessary
	// to clear selection) will move vertical scroll bar
	if (unselectAll) {
		cursor.clearSelection();
		ptv->setTextCursor(cursor);
		ptv->verticalScrollBar()->setValue(position);
	}
	
	return result;
}
예제 #3
0
QString PsiTextView::getTextHelper(bool html) const
{
	PsiTextView *ptv = (PsiTextView *)this;
	QTextCursor cursor = ptv->textCursor();
	int position = ptv->verticalScrollBar()->value();

	bool unselectAll = false;
	if (!textCursor().hasSelection()) {
#if QT_VERSION == 0x040701
		// workaround for crash when deleting last character with backspace (qt-4.7.1)
		// http://bugreports.qt.nokia.com/browse/QTBUG-15857
		QTextCursor tempCursor = QTextCursor(ptv->document());
		tempCursor.movePosition(QTextCursor::Start);
		ptv->setTextCursor(tempCursor);
#endif
		ptv->selectAll();
		unselectAll = true;
	}

	QMimeData *mime = createMimeDataFromSelection();
	QString result;
	if (html)
		result = mime->html();
	else
		result = mime->text();
	delete mime;

	// we need to restore original position if selectAll()
	// was called, because setTextCursor() (which is necessary
	// to clear selection) will move vertical scroll bar
	if (unselectAll) {
		cursor.clearSelection();
		ptv->setTextCursor(cursor);
		ptv->verticalScrollBar()->setValue(position);
	}

	return result;
}