Exemplo n.º 1
0
void MainWindow::previewSvg(const QString & link)
{
    if (!LQListWidget->currentIndex().isValid()) { return; }
        QuestionItem * item = current_test_questions.value(LQListWidget->currentItem());
        if (item == NULL) { return; }
    int i_link = link.toInt();
        if (i_link < 0 || i_link >= item->numSvgItems()) { return; }
        QSvgRenderer temp(item->svg(i_link).toUtf8());
        if( temp.isValid() )
        {
            QSvgWidget * svg_widget = new QSvgWidget;
                svg_widget->setAttribute(Qt::WA_DeleteOnClose);
                svg_widget->setParent(this);
        #ifndef Q_WS_MAC
                svg_widget->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint);
        #else
                svg_widget->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint | Qt::WindowSystemMenuHint);
        #endif
                svg_widget->setWindowTitle(item->svgName(i_link));
                QSize minimum_size = svg_widget->sizeHint();
                minimum_size.scale(128, 128, Qt::KeepAspectRatioByExpanding);
                svg_widget->setMinimumSize(minimum_size);
             //   svg_widget->setMaximumSize(minimum_size);
                svg_widget->load(item->svg(i_link).toUtf8());
                svg_widget->show();
        }
        else //bitmap
        {
            BitmapWidget *bit_widget = new BitmapWidget;

               bit_widget->setAttribute(Qt::WA_DeleteOnClose);
               bit_widget->setParent(this);
        #ifndef Q_WS_MAC
                bit_widget->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint);
        #else
                bit_widget->setWindowFlags(Qt::Dialog | Qt::WindowMaximizeButtonHint | Qt::WindowStaysOnTopHint | Qt::WindowSystemMenuHint);
        #endif
                bit_widget->setWindowTitle(item->svgName(i_link));

                QSize minimum_size(128,128);
                minimum_size.scale(128, 128, Qt::KeepAspectRatioByExpanding);
                bit_widget->setMinimumSize(minimum_size);

            //   bit_widget->setMaximumSize(minimum_size);

                bit_widget->load(item->svg(i_link).toUtf8());
                bit_widget->show();
        }

}
Exemplo n.º 2
0
void MainWindow::setCurrentQuestion()
{
     if (LQListWidget->currentIndex().isValid()) {
        questionTextBrowser->clear();
        answersView->setEnabled(true);
        QuestionItem *item = current_test_questions.value(LQListWidget->currentItem());
        questionTextBrowser->setHtml(item->text());
        answersView->setAnswers(item->answers(), item->answered(), item->selectionType(), item->answerOrder());
        svgDisplayWidget->clear();
        if (item->numSvgItems() > 0) {
            svgDisplayWidget->setVisible(true);
            //int h = 0;
            for (int i = 0; i < item->numSvgItems(); ++i) {
                QSvgWidget *svg_widget = new QSvgWidget;
                QSize minimum_size = svg_widget->sizeHint();
                minimum_size.scale(128, 128, Qt::KeepAspectRatioByExpanding);
                svg_widget->setMinimumSize(minimum_size);
                svg_widget->load(item->svg(i).toUtf8());
                /*if (svg_widget->renderer()->defaultSize().height() + 40 > h) {
                    h = svg_widget->renderer()->defaultSize().height() + 40;
                }*/
                svgDisplayWidget->addWidget(svg_widget, item->svgName(i), true);
            }
            //if (h < 168) { h = 168; }
            qApp->processEvents();
            questionTextSvgSplitter->moveSplitter(questionTextSvgSplitter->height()-svgDisplayWidget->layoutHeightForWidth(questionTextSvgSplitter->width()));
        } else {
            svgDisplayWidget->setVisible(false);
        }
        if (LQListWidget->currentRow() >= (LQListWidget->count()-1)) {
            btnNext->setEnabled(false);
        } else {
            btnNext->setEnabled(true);
        }
        if (LQListWidget->currentRow() <= 0) {
            btnLast->setEnabled(false);
        } else {
            btnLast->setEnabled(true);
        }
     } else {
        questionTextBrowser->clear();
        answersView->clear();
        answersView->setEnabled(false);
        svgDisplayWidget->clear();
        btnNext->setEnabled(false);
        btnLast->setEnabled(false);
     }
}