int KMessageBox::createKMessageBox(KDialog *dialog, const QIcon &icon, const QString &text, const QStringList &strlist, const QString &ask, bool *checkboxReturn, Options options, const QString &details, QMessageBox::Icon notifyType) { QWidget *mainWidget = new QWidget(dialog); QVBoxLayout *mainLayout = new QVBoxLayout(mainWidget); mainLayout->setSpacing(KDialog::spacingHint() * 2); // provide extra spacing mainLayout->setMargin(0); QHBoxLayout *hLayout = new QHBoxLayout(); hLayout->setMargin(0); hLayout->setSpacing(-1); // use default spacing mainLayout->addLayout(hLayout,5); QLabel *iconLabel = new QLabel(mainWidget); if (!icon.isNull()) { QStyleOption option; option.initFrom(mainWidget); iconLabel->setPixmap(icon.pixmap(mainWidget->style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, mainWidget))); } QVBoxLayout *iconLayout = new QVBoxLayout(); iconLayout->addStretch(1); iconLayout->addWidget(iconLabel); iconLayout->addStretch(5); hLayout->addLayout(iconLayout,0); hLayout->addSpacing(KDialog::spacingHint()); QLabel *messageLabel = new QLabel(text, mainWidget); messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink); Qt::TextInteractionFlags flags = Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard; if (options & KMessageBox::AllowLink) { flags |= Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard; } messageLabel->setTextInteractionFlags(flags); QRect desktop = KGlobalSettings::desktopGeometry(dialog); bool usingSqueezedTextLabel = false; if (messageLabel->sizeHint().width() > desktop.width() * 0.5) { // enable automatic wrapping of messages which are longer than 50% of screen width messageLabel->setWordWrap(true); // display a text widget with scrollbar if still too wide usingSqueezedTextLabel = messageLabel->sizeHint().width() > desktop.width() * 0.85; if (usingSqueezedTextLabel) { delete messageLabel; messageLabel = new KSqueezedTextLabel(text, mainWidget); messageLabel->setOpenExternalLinks(options & KMessageBox::AllowLink); messageLabel->setTextInteractionFlags(flags); } } QPalette messagePal(messageLabel->palette()); messagePal.setColor(QPalette::Window, Qt::transparent); messageLabel->setPalette(messagePal); bool usingScrollArea=desktop.height() / 3 < messageLabel->sizeHint().height(); if (usingScrollArea) { QScrollArea* messageScrollArea = new QScrollArea(mainWidget); messageScrollArea->setWidget(messageLabel); messageScrollArea->setFrameShape(QFrame::NoFrame); messageScrollArea->setWidgetResizable(true); QPalette scrollPal(messageScrollArea->palette()); scrollPal.setColor(QPalette::Window, Qt::transparent); messageScrollArea->viewport()->setPalette(scrollPal); hLayout->addWidget(messageScrollArea,5); } else hLayout->addWidget(messageLabel,5); const bool usingListWidget=!strlist.isEmpty(); if (usingListWidget) { // enable automatic wrapping since the listwidget has already a good initial width messageLabel->setWordWrap(true); QListWidget *listWidget = new QListWidget(mainWidget); listWidget->addItems(strlist); QStyleOptionViewItem styleOption; styleOption.initFrom(listWidget); QFontMetrics fm(styleOption.font); int w = listWidget->width(); Q_FOREACH(const QString &str, strlist) { w = qMax(w, fm.width(str)); } const int borderWidth = listWidget->width() - listWidget->viewport()->width() + listWidget->verticalScrollBar()->height(); w += borderWidth; if (w > desktop.width() * 0.85) { // limit listWidget size to 85% of screen width w = qRound(desktop.width() * 0.85); } listWidget->setMinimumWidth(w); mainLayout->addWidget(listWidget,usingScrollArea?10:50); listWidget->setSelectionMode(QListWidget::NoSelection); messageLabel->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Minimum); }
MainWidget::MainWidget(QWidget *parent) : QWidget(parent) { //init color palette for variables VariableColorPalette palette(QColor(50,100,200)); preview = new CubeMapPreview(500); loader = new CubeMapLoader(); curveEditor = new CurveEditor(this); curveEditor->setViewScale(0.1,-1); setEditorRange(100); curveEditor->setSnap(1,0); curveEditor->setCurrentFrame(0); //create and init variables CurveVariable * pitch = new CurveVariable("Pitch"); CurveVariable * yaw = new CurveVariable("Yaw"); CurveVariable * roll = new CurveVariable("Roll"); CurveVariable * zoom = new CurveVariable("Zoom"); CurveVariable * fov = new CurveVariable("Fov",180); CurveVariable * frame = new CurveVariable("Cubemap",0); //add variables to key frames watcher KeyFrames * keyFrames = KeyFrames::getInstance(); keyFrames->addVariable(pitch); keyFrames->addVariable(zoom); keyFrames->addVariable(roll); keyFrames->addVariable(fov); keyFrames->addVariable(yaw); keyFrames->addVariable(frame); curveEditor->addVariable(pitch); curveEditor->addVariable(yaw); curveEditor->addVariable(roll); curveEditor->addVariable(zoom); curveEditor->addVariable(fov); curveEditor->addVariable(frame); preview->setPitchVar(pitch); preview->setFovVar(fov); preview->setYawVar(yaw); preview->setRollVar(roll); preview->setZoomVar(zoom); loader->setFrameVar(frame); //setup time line timeLine = new TimeLine(this); //init IO module importExport = new IOWidget(loader, timeLine, this); //let the timeline know that a frame has been keyed/un keyed connect(pitch,SIGNAL(changed(float,float)), timeLine, SLOT(update())); connect(yaw,SIGNAL(changed(float,float)), timeLine, SLOT(update())); connect(roll,SIGNAL(changed(float,float)), timeLine, SLOT(update())); connect(zoom,SIGNAL(changed(float,float)), timeLine, SLOT(update())); connect(fov,SIGNAL(changed(float,float)), timeLine, SLOT(update())); connect(frame,SIGNAL(changed(float,float)), timeLine, SLOT(update())); //update preview when cube map changes connect(loader,SIGNAL(faceChanged(QImage *,CubeFace)),preview,SLOT(setFace(QImage *, CubeFace))); //tells the cube map loader to load the cube map corresponding to the new frame connect(timeLine,SIGNAL(frameChanged(float)),loader,SLOT(variablesValues(float))); //tells the preview to display a new frame connect(timeLine,SIGNAL(frameChanged(float)),preview,SLOT(variablesValues(float))); //update the frame cursor of the curve editor connect(timeLine,SIGNAL(frameChanged(float)),curveEditor,SLOT(setCurrentFrame(float))); //Change the range of frames displayed by the curvor editor when the number of frames changes connect(timeLine,SIGNAL(frameNumberChanged(int)), this, SLOT(setEditorRange(int))); //Refresh preview when curves have been edited connect(curveEditor,SIGNAL(curvesChanged(float, float)),preview,SLOT(refreshVariablesValues(float, float))); //connect(timeLine,SIGNAL(frameChanged(float)),preview,SLOT(refresh())); //stop playback if the user interacts with the preview connect(preview,SIGNAL(previewChanged()),timeLine,SLOT(stop())); QTabWidget * tabWidget = new QTabWidget(this); tabWidget->addTab(loader,"Cube&map"); tabWidget->addTab(curveEditor,"Curve &Editor"); tabWidget->addTab(importExport,"E&xport"); QScrollArea * previewScroll = new QScrollArea(this); previewScroll->setWidget(preview); previewScroll->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); QPalette pal = previewScroll->palette(); pal.setColor(QPalette::Background,Qt::black); previewScroll->setPalette(pal); QScrollArea * tabScroll = new QScrollArea(this); tabScroll->setWidget(tabWidget); //so the content will expand if possible tabScroll->setWidgetResizable(true); QSplitter * splitterH = new QSplitter(Qt::Horizontal); splitterH->addWidget(previewScroll); splitterH->addWidget(tabScroll); //splitterH->addWidget(tabWidget); //splitterH->setStretchFactor(0,1); splitterH->setStretchFactor(1,1); QSplitter * splitterV = new QSplitter(Qt::Vertical); splitterV->addWidget(splitterH); splitterV->addWidget(timeLine); splitterV->setStretchFactor(0,1); QGridLayout * gridLayout = new QGridLayout(); gridLayout->addWidget(splitterV,0,0); setLayout(gridLayout); //load settings readSettings(); }