int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

    QTextDocument *document = new QTextDocument(editor);
    QTextCursor cursor(document);

    QImage image(64, 64, QImage::Format_RGB32);
    image.fill(qRgb(255, 160, 128));

//! [Adding a resource]
    document->addResource(QTextDocument::ImageResource,
        QUrl("mydata://image.png"), QVariant(image));
//! [Adding a resource]

//! [Inserting an image with a cursor]
    QTextImageFormat imageFormat;
    imageFormat.setName("mydata://image.png");
    cursor.insertImage(imageFormat);
//! [Inserting an image with a cursor]

    cursor.insertBlock();
    cursor.insertText("Code less. Create more.");

    editor->setDocument(document);
    editor->setWindowTitle(tr("Text Document Images"));
    editor->resize(320, 480);
    editor->show();

//! [Inserting an image using HTML]
    editor->append("<img src=\"mydata://image.png\" />");
//! [Inserting an image using HTML]

    return app.exec();
}
Exemplo n.º 2
0
void DPText::drawShape( QPainter &p )
{
	QRect bound = m_sizeRect;
	bound.setWidth( bound.width()-2 );
	bound.setHeight( bound.height()-2 );
	bound.translate( int(x()+1), int(y()+1) );
	
	if (b_displayBackground)
	{
		p.save();
		p.setPen( QPen( m_frameColor, 1, Qt::DotLine) );
		p.setBrush(m_backgroundColor);
		p.drawRect(bound);
		p.restore();
	}
	
	const int pad = 6;
	
	bound.setLeft( bound.left()+pad );
	bound.setTop( bound.top() );
	bound.setRight( bound.right()-pad );
	bound.setBottom( bound.bottom()-pad );
	
	QTextEdit * t = new QTextEdit( m_text );
    t->resize( bound.width(), bound.height() ); // t->setWidth( bound.width() );
    t->viewport()->setAutoFillBackground( false );
    t->setFrameStyle(QFrame::NoFrame);

    t->render( &p, bound.topLeft(), QRegion(), QWidget::DrawChildren ); //t->draw( &p, bound.left(), bound.top(), bound, QColorGroup() );
	delete t;
}
Exemplo n.º 3
0
// ----------------------------------------------------------------------
//->setWindowFlags(Qt::Window | Qt::WindowTitleHint);
//->setWindowFlags(Qt::Window | Qt::WindowSystemMenuHint);
// ----------------------------------------------------------------------
void WxMain::slotActivHelp(){
//    QString str = ((QPushButton*)sender())->text();
//    if (str == tr("Справка")){
        QTextEdit *txt = new QTextEdit;
        txt->setReadOnly(true);
	txt->setHtml( tr("<HTML>"
                "<BODY>"
                "<H2><CENTER> Справка </CENTER></H2>"
                "<P ALIGN=\"left\">"
                    "<BR>"
                    "<BR>"
                    "<BR>"
        	"</P>"
                "<H3><CENTER> Версия 1.2 </CENTER></H3>"
                "<H4><CENTER> Октябрьь 2013 </CENTER></H4>"
                "<H4><CENTER> Широков О.Ю. </CENTER></H4>"
                "<BR>"
                "</BODY>"
                "</HTML>"
               ));
        txt->resize(250, 200);
        txt->show();
//                "<BODY BGCOLOR=MAGENTA>"
//                "<FONT COLOR=BLUE>"
//                "</FONT>"
//    }
//    qDebug() << tr("Справка");  
return;
}// End slot
Exemplo n.º 4
0
Arquivo: main.cpp Projeto: Afreeca/qt
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

//! [0]
    QTextDocument *document = editor->document();
    QTextCursor redCursor(document);
//! [0] //! [1]
    QTextCursor blueCursor(document);
//! [1]

    QTextCharFormat redFormat(redCursor.charFormat());
    redFormat.setForeground(Qt::red);
    QTextCharFormat blueFormat(blueCursor.charFormat());
    blueFormat.setForeground(Qt::blue);

    redCursor.setCharFormat(redFormat);
    blueCursor.setCharFormat(blueFormat);

    for (int i = 0; i < 20; ++i) {
        if (i % 2 == 0)
            redCursor.insertText(tr("%1 ").arg(i), redFormat);
        if (i % 5 == 0)
            blueCursor.insertText(tr("%1 ").arg(i), blueFormat);
    }

    editor->setWindowTitle(tr("Text Document Cursors"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

//! [0]
    QTextDocument *document = new QTextDocument(editor);
    QTextCursor cursor(document);
//! [0]

//! [1]
    QTextImageFormat imageFormat;
    imageFormat.setName(":/images/advert.png");
    cursor.insertImage(imageFormat);
//! [1]

    cursor.insertBlock();
    cursor.insertText("Code less. Create more.");

    editor->setDocument(document);
    editor->setWindowTitle(tr("Text Document Images"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
Exemplo n.º 6
0
  void FQTermImageOrigin::showFullExifInfo() {

    QString exifInfo = QString::fromStdString(exifExtractor_->extractExifInfo(model_->filePath(tree_->currentIndex()).toLocal8Bit().data()));
    QString comment;

    if ((*exifExtractor_)["UserComment"].length() > 8) {

      QString commentEncoding = QString::fromStdString((*exifExtractor_)["UserComment"].substr(0, 8));

      if (commentEncoding.startsWith("UNICODE")) {
        //UTF-16
        QTextCodec* c = QTextCodec::codecForName("UTF-16");
        comment = c->toUnicode((*exifExtractor_)["UserComment"].substr(8).c_str());
      } else if (commentEncoding.startsWith("JIS")) {
        //JIS X 0208
        QTextCodec* c = QTextCodec::codecForName("JIS X 0208");
        comment = c->toUnicode((*exifExtractor_)["UserComment"].substr(8).c_str());
      } else {
        comment = QString::fromStdString((*exifExtractor_)["UserComment"].substr(8));
      }
    }


    QTextEdit* info = new QTextEdit;
    info->setText(exifInfo + tr("Comment : ") + comment + "\n");
    info->setWindowFlags(Qt::Dialog);
    info->setAttribute(Qt::WA_DeleteOnClose);
    info->setAttribute(Qt::WA_ShowModal);
    //  info->setLineWrapMode(QTextEdit::NoWrap);
    info->setReadOnly(true);
    QFontMetrics fm(font());
    info->resize(fm.width("Orientation : 1st row - 1st col : top - left side    "), fm.height() * 20);
    info->show();
  }
Exemplo n.º 7
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

    QTextDocument *document = new QTextDocument(editor);
    QTextCursor cursor(document);

    QTextImageFormat imageFormat;
    imageFormat.setName(":/images/advert.png");
    cursor.insertImage(imageFormat);

    QTextBlock block = cursor.block();
    QTextFragment fragment;
    QTextBlock::iterator it;

    for (it = block.begin(); !(it.atEnd()); ++it) {
        fragment = it.fragment();

        if (fragment.contains(cursor.position()))
            break;
    }

//! [0]
    if (fragment.isValid()) {
        QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();

        if (newImageFormat.isValid()) {
            newImageFormat.setName(":/images/newimage.png");
            QTextCursor helper = cursor;

            helper.setPosition(fragment.position());
            helper.setPosition(fragment.position() + fragment.length(),
                               QTextCursor::KeepAnchor);
            helper.setCharFormat(newImageFormat);
//! [0] //! [1]
        }
//! [1] //! [2]
    }
//! [2]

    cursor.insertBlock();
    cursor.insertText("Code less. Create more.");

    editor->setDocument(document);
    editor->setWindowTitle(tr("Text Document Image Format"));
    editor->resize(320, 480);
    editor->show();

    return app.exec();
}
Exemplo n.º 8
0
void QtAboutWidget::handleLicenseClicked() {
	QTextEdit* text = new QTextEdit();
	text->setAttribute(Qt::WA_DeleteOnClose);
	text->setReadOnly(true);
	QFile file(":/COPYING");
	file.open(QIODevice::ReadOnly);
	QTextStream in(&file);
	in.setCodec("UTF-8");
	text->setPlainText(in.readAll());
	file.close();
	text->resize(500, 600);
	text->show();
	text->activateWindow();
}
Exemplo n.º 9
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit();

    QTextCursor cursor(editor->textCursor());
    cursor.movePosition(QTextCursor::Start); 

    QTextCharFormat plainFormat(cursor.charFormat());

    QTextCharFormat headingFormat = plainFormat;
    headingFormat.setFontWeight(QFont::Bold);
    headingFormat.setFontPointSize(16);

    QTextCharFormat emphasisFormat = plainFormat;
    emphasisFormat.setFontItalic(true);

    QTextCharFormat qtFormat = plainFormat;
    qtFormat.setForeground(QColor("#990000"));

    QTextCharFormat underlineFormat = plainFormat;
    underlineFormat.setFontUnderline(true);

//! [0]
    cursor.insertText(tr("Character formats"),
                      headingFormat);

    cursor.insertBlock();

    cursor.insertText(tr("Text can be displayed in a variety of "
                                  "different character formats. "), plainFormat);
    cursor.insertText(tr("We can emphasize text by "));
    cursor.insertText(tr("making it italic"), emphasisFormat);
//! [0]
    cursor.insertText(tr(", give it a "), plainFormat);
    cursor.insertText(tr("different color "), qtFormat);
    cursor.insertText(tr("to the default text color, "), plainFormat);
    cursor.insertText(tr("underline it"), underlineFormat);
    cursor.insertText(tr(", and use many other effects."), plainFormat);

    editor->setWindowTitle(tr("Text Document Character Formats"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit();

    QTextCursor cursor(editor->textCursor());
    cursor.movePosition(QTextCursor::Start);

    QTextCharFormat plainFormat(cursor.charFormat());
    QTextCharFormat colorFormat = plainFormat;
    colorFormat.setForeground(Qt::red);

    cursor.insertText(tr("Text can be displayed in a variety of "
                                  "different character "
                                  "formats. "), plainFormat);
    cursor.insertText(tr("We can emphasize text by making it "));
    cursor.insertText(tr("italic, give it a different color "));
    cursor.insertText(tr("to the default text color, underline it, "));
    cursor.insertText(tr("and use many other effects."));

    QString searchString = tr("text");

    QTextDocument *document = editor->document();
//! [0]
    QTextCursor newCursor(document);

    while (!newCursor.isNull() && !newCursor.atEnd()) {
        newCursor = document->find(searchString, newCursor);

        if (!newCursor.isNull()) {
            newCursor.movePosition(QTextCursor::WordRight,
                                   QTextCursor::KeepAnchor);

            newCursor.mergeCharFormat(colorFormat);
        }
//! [0] //! [1]
    }
//! [1]

    editor->setWindowTitle(tr("Text Document Find"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
Exemplo n.º 11
0
QVariant SnippetCompletionItem::data( const QModelIndex& index, int role, const KTextEditor::CodeCompletionModel2* model ) const
{
    // as long as the snippet completion model is not a kdevelop code completion model,
    // model will usually be 0. hence don't use it.
    Q_UNUSED(model);

    switch ( role ) {
    case Qt::DisplayRole:
        switch ( index.column() ) {
            case KTextEditor::CodeCompletionModel::Name:
                return m_name;
            case KTextEditor::CodeCompletionModel::Prefix:
                return m_prefix;
            case KTextEditor::CodeCompletionModel::Postfix:
                return m_postfix;
            case KTextEditor::CodeCompletionModel::Arguments:
                return m_arguments;
        }
        break;
    case KTextEditor::CodeCompletionModel::IsExpandable:
        return QVariant(true);
    case KTextEditor::CodeCompletionModel::ExpandingWidget:
        {
        QTextEdit *textEdit = new QTextEdit();
        ///TODO: somehow make it possible to scroll like in other expanding widgets
        // don't make it too large, only show a few lines
        textEdit->resize(textEdit->width(), 100);
        textEdit->setPlainText(m_snippet);
        textEdit->setReadOnly(true);
        textEdit->setLineWrapMode(QTextEdit::NoWrap);

        QVariant v;
        v.setValue<QWidget*>(textEdit);
        return v;
        }
    }

    return QVariant();
}
void ComputationalResultsTableView::showLogFile()
{
  MongoDatabase *db = MongoDatabase::instance();
  mongo::GridFS fs(*db->connection(), "chem", "fs");

  mongo::BSONObj *obj =
    static_cast<mongo::BSONObj *>(currentIndex().internalPointer());
  if (obj) {
    const char *file_name = obj->getStringField("log_file");

    mongo::GridFile file = fs.findFile(file_name);

    if (!file.exists()) {
      QMessageBox::critical(this,
                            "Error",
                            "Failed to load output file.");
      return;
    }

    // load file into a buffer
    std::stringstream stream;
    file.write(stream);

    QTextEdit *viewer = new QTextEdit(this);
    viewer->resize(500, 600);
    viewer->setWindowFlags(Qt::Dialog);
    viewer->setWindowTitle(file_name);
    viewer->setReadOnly(true);
    std::string file_data_string = stream.str();
    viewer->setText(file_data_string.c_str());
    viewer->show();
  }
  else {
    QMessageBox::critical(this,
                          "Error",
                          "Failed to load output file.");
  }
}
Exemplo n.º 13
0
void Dialog::appendToHistory(const QString& name, const QDateTime& sendTime, QTextDocument *document, InsertingMode mode) {
    QListWidgetItem *item = new QListWidgetItem();
    QTextEdit *te = new QTextEdit();
    lwHistory->addItem(item);
    te->setReadOnly(true);
    reloadResource(te);
    lwHistory->setItemWidget(item, te);
    QString color;
    if (name == "You")
        color = "blue";
    else
        color = "red";

    te->append(QString("<font color = \"%1\"> <b>" + name + "</b> (" + sendTime.toString("dd-MM-yyyy hh:mm:ss") + "):</font>").arg(color));
    te->moveCursor(QTextCursor::End);
    te->textCursor().insertBlock();
    te->textCursor().insertFragment(QTextDocumentFragment(document));

    int heig = 17, widthTe = parentWidget()->width();
    int curLine = 0;
    int mx = 0;

    for (QTextBlock bl = te->document()->begin(); bl != te->document()->end(); bl = bl.next())
        if (bl.isValid()) {
            if (bl.begin().atEnd()) {
                heig += 17 + mx;//&&&
                curLine = mx = 0;
                continue;
            }

            for (QTextBlock::iterator it = bl.begin(); !it.atEnd(); ++it) {
                QTextFragment fragm = it.fragment();
                int curw, curh;
                if (fragm.isValid() && fragm.charFormat().isImageFormat()) {
                    curw = smiles->width() / W_CNT;
                    curh = smiles->height() / H_CNT;
                    processCalc(heig, mx, curLine, curw, curh);
                } else if (fragm.isValid()) {
                    QString s = fragm.text();
                    QFontMetrics me(fragm.charFormat().font());
                    curh = me.lineSpacing();
                    for (int j = 0; j < s.size(); ++j) {
                        curw = me.width(s[j]);
                        processCalc(heig, mx, curLine, curw, curh);
                    }
                }
            }
            heig += mx;
            mx = curLine = 0;
        }

    te->setStyleSheet(QString("QFrame {"
                 "border: 2px solid #f3f2f1;"
                 "border-radius: 4px;"
                  "padding: 2px;}"));
    item->setSizeHint(QSize(0, heig + 18));
    te->resize(QSize(widthTe, heig));
    lwHistory->scrollToBottom();

    if (mode == ReceivedMessage && !dgReadByUser) {
        setUnreadMessage(unreadMessage + 1);
        queUnreadWrote.push_back(te);
        te->setStyleSheet("QTextEdit { background-color: #FFFCCC; }");
    } else if (mode == LoadHistory) {

        if (unreadMessage != 0) {
            queUnreadWrote.push_back(te);
            te->setStyleSheet("QTextEdit { background-color: #FFFCCC; }");
            if (queUnreadWrote.size() > unreadMessage) {
                queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }");
                queUnreadWrote.pop_front();
            }
        }

        if (wroteMessage != 0) {
            queUnreadWrote.push_back(te);
            te->setStyleSheet("QTextEdit { background-color: #DFFFCC; }");
            if (queUnreadWrote.size() > wroteMessage) {
                queUnreadWrote.front()->setStyleSheet("QTextEdit { background-color: #FFFFFF; }");
                queUnreadWrote.pop_front();
            }
        }

    } else if (mode == SendMessage) {
        teMessage->setFocus();
        te->setStyleSheet("QTextEdit { background-color: #DFFFCC; }");
        wroteMessage++;
        queUnreadWrote.push_back(te);
    }
}
Exemplo n.º 14
0
Arquivo: main.cpp Projeto: cedrus/qt4
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

//! [0]
    QTextEdit *editor = new QTextEdit();
    QTextCursor cursor(editor->textCursor());
//! [0]
    cursor.movePosition(QTextCursor::Start);

    QTextBlockFormat blockFormat = cursor.blockFormat();
    blockFormat.setTopMargin(4);
    blockFormat.setLeftMargin(4);
    blockFormat.setRightMargin(4);
    blockFormat.setBottomMargin(4);

    cursor.setBlockFormat(blockFormat);
    cursor.insertText(tr("This contains plain text inside a "
                         "text block with margins to keep it separate "
                         "from other parts of the document."));

    cursor.insertBlock();

//! [1]
    QTextBlockFormat backgroundFormat = blockFormat;
    backgroundFormat.setBackground(QColor("lightGray"));

    cursor.setBlockFormat(backgroundFormat);
//! [1]
    cursor.insertText(tr("The background color of a text block can be "
                         "changed to highlight text."));

    cursor.insertBlock();

    QTextBlockFormat rightAlignedFormat = blockFormat;
    rightAlignedFormat.setAlignment(Qt::AlignRight);

    cursor.setBlockFormat(rightAlignedFormat);
    cursor.insertText(tr("The alignment of the text within a block is "
                         "controlled by the alignment properties of "
                         "the block itself. This text block is "
                         "right-aligned."));

    cursor.insertBlock();

    QTextBlockFormat paragraphFormat = blockFormat;
    paragraphFormat.setAlignment(Qt::AlignJustify);
    paragraphFormat.setTextIndent(32);

    cursor.setBlockFormat(paragraphFormat);
    cursor.insertText(tr("Text can be formatted so that the first "
                         "line in a paragraph has its own margin. "
                         "This makes the text more readable."));

    cursor.insertBlock();

    QTextBlockFormat reverseFormat = blockFormat;
    reverseFormat.setAlignment(Qt::AlignJustify);
    reverseFormat.setTextIndent(32);

    cursor.setBlockFormat(reverseFormat);
    cursor.insertText(tr("The direction of the text can be reversed. "
                         "This is useful for right-to-left "
                         "languages."));

    editor->setWindowTitle(tr("Text Block Formats"));
    editor->resize(480, 480);
    editor->show();

    return app.exec();
}