// Extract the wrapped text from a text edit, which performs // the wrapping only optically. void SubmitEditorWidget::wrapDescription() { if (!lineWrap()) return; const QChar newLine = QLatin1Char('\n'); QTextEdit e; e.setVisible(false); e.setMinimumWidth(1000); e.setFontPointSize(1.0); e.setLineWrapColumnOrWidth(d->m_ui.description->lineWrapColumnOrWidth()); e.setLineWrapMode(d->m_ui.description->lineWrapMode()); e.setWordWrapMode(d->m_ui.description->wordWrapMode()); e.setPlainText(d->m_description); d->m_description.clear(); QTextCursor cursor(e.document()); cursor.movePosition(QTextCursor::Start); while (!cursor.atEnd()) { const QString block = cursor.block().text(); if (block.startsWith(QLatin1Char('\t'))) { // Don't wrap d->m_description += block + newLine; cursor.movePosition(QTextCursor::EndOfBlock); } else { forever { cursor.select(QTextCursor::LineUnderCursor); d->m_description += cursor.selectedText(); d->m_description += newLine; cursor.clearSelection(); if (cursor.atBlockEnd()) break; cursor.movePosition(QTextCursor::NextCharacter); } } cursor.movePosition(QTextCursor::NextBlock); } }
QWidget* AboutBox::createLicensePanel() { // Create a label to display readme.txt QTextEdit* label = new QTextEdit(); label->setReadOnly(true); QString fileName(QString::fromUtf8(m_gleInterface->getManualLocation().c_str())); fileName.resize(fileName.lastIndexOf(QDir::separator())); fileName += QDir::separator(); fileName += tr("LICENSE.txt"); GLEInterface* iface = GLEGetInterfacePointer(); std::string licenseFileTxt; bool res = iface->readFileOrGZIPTxt(fileName.toUtf8().constData(), &licenseFileTxt); if (res) { QFont font; // Set the font to be fixed pitch font.setFixedPitch(true); font.setFamily("Courier"); font.setStretch(QFont::Condensed); label->setLineWrapMode(QTextEdit::NoWrap); label->setFont(font); label->setTextColor(Qt::black); // Get the text and put it in the label label->setPlainText(licenseFileTxt.c_str()); QFontMetrics fm(font); m_minWidth = fm.width("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); } else { label->setPlainText(tr("File not found: '%1'").arg(fileName)); } return label; }
LicenseDialog::LicenseDialog(QWidget *parent) :QDialog(parent, Qt::WindowCloseButtonHint) { QFile file(QLatin1String(":/traceshark/LICENSE")); if (!file.open(QIODevice::ReadOnly)) qDebug() << "Warning, could not read license!\n"; QTextStream textStream(&file); QString text = textStream.readAll(); QTextEdit *textEdit = new QTextEdit(); textEdit->setAcceptRichText(false); textEdit->setPlainText(text); textEdit->setReadOnly(true); textEdit->setLineWrapMode(QTextEdit::NoWrap); QVBoxLayout *vlayout = new QVBoxLayout; setLayout(vlayout); vlayout->addWidget(textEdit); QHBoxLayout *hlayout = new QHBoxLayout; vlayout->addLayout(hlayout); hlayout->addStretch(); QPushButton *button = new QPushButton(tr("OK")); hlayout->addWidget(button); hlayout->addStretch(); setModal(true); updateSize(); hide(); tsconnect(button, clicked(), this, hide()); }
ScrollBarSettingsEditor::ScrollBarSettingsEditor(QWidget *parent) : QWidget(parent), ui(new Ui::ScrollBarSettingsForm), m_verticalScrollbar(new QtMaterialScrollBar), m_horizontalScrollbar(new QtMaterialScrollBar) { QVBoxLayout *layout = new QVBoxLayout; setLayout(layout); QWidget *widget = new QWidget; layout->addWidget(widget); QWidget *canvas = new QWidget; canvas->setStyleSheet("QWidget { background: white; }"); layout->addWidget(canvas); ui->setupUi(widget); layout->setContentsMargins(20, 20, 20, 20); layout = new QVBoxLayout; canvas->setLayout(layout); canvas->setMaximumHeight(400); QTextEdit *edit = new QTextEdit; edit->setText("<p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p><p>The distinction between the subjects of syntax and semantics has its origin in the study of natural languages.</p>"); edit->setLineWrapMode(QTextEdit::NoWrap); edit->update(); edit->setMaximumHeight(200); edit->setVerticalScrollBar(m_verticalScrollbar); edit->setHorizontalScrollBar(m_horizontalScrollbar); //m_verticalScrollbar->setHideOnMouseOut(false); //m_horizontalScrollbar->setHideOnMouseOut(false); m_horizontalScrollbar->setOrientation(Qt::Horizontal); layout->addWidget(edit); layout->setAlignment(edit, Qt::AlignHCenter); setupForm(); }
/** * Constructor. * * @param message The error message to be displayed * @param data The line of CSV data which triggered the error * @param parent The parent widget, if any */ CSVErrorDialog::CSVErrorDialog(const QString &message, const QString &data, QWidget *parent) : PBDialog("", parent) { vbox->addWidget(new QLabel(message, this)); vbox->addWidget(new QLabel(tr("Problematic row") + ":", this)); QTextEdit *dataBox = new QTextEdit(parent); dataBox->setReadOnly(true); #if defined(Q_WS_MAEMO_5) QVariant ksProp = dataBox->property("kineticScroller"); QAbstractKineticScroller *ks = ksProp.value<QAbstractKineticScroller *>(); if (ks) { ks->setEnabled(true); } #endif dataBox->setLineWrapMode(QTextEdit::NoWrap); dataBox->setPlainText(data); vbox->addWidget(dataBox); finishLayout(true, false); }
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(); }
TrayNotificationWidget::TrayNotificationWidget(QPixmap pixmapIcon, QString headerText, QString messageText) : QWidget(0) { setWindowFlags( #ifdef Q_OS_MAC Qt::SubWindow | // This type flag is the second point #else Qt::Tool | #endif Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowStaysOnTopHint ); setAttribute(Qt::WA_NoSystemBackground, true); // set the parent widget's background to translucent setAttribute(Qt::WA_TranslucentBackground, true); //setAttribute(Qt::WA_ShowWithoutActivating, true); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); // create a display widget for displaying child widgets QWidget* displayWidget = new QWidget; displayWidget->setStyleSheet(".QWidget { background-color: rgba(0, 0, 0, 75%); border-width: 1px; border-style: solid; border-radius: 10px; border-color: #555555; } .QWidget:hover { background-color: rgba(68, 68, 68, 75%); border-width: 2px; border-style: solid; border-radius: 10px; border-color: #ffffff; }"); QLabel* icon = new QLabel; icon->setPixmap(pixmapIcon); icon->setMaximumSize(32, 32); QLabel* header = new QLabel; header->setMaximumSize(250, 50); header->setWordWrap(true); header->setText(headerText); header->setStyleSheet("QLabel { color: #ffffff; font-weight: bold; font-size: 12px; }"); QTextEdit *message = new QTextEdit; message->setReadOnly(true); message->setFrameStyle(QFrame::NoFrame); message->setLineWrapMode(QTextEdit::WidgetWidth); message->setWordWrapMode(QTextOption::WrapAnywhere); QPalette pal = palette(); pal.setColor(QPalette::Base, Qt::transparent); message->setPalette(pal); message->setStyleSheet("QTextEdit { color: #ffffff; font-size: 10px; }"); message->setText(messageText); message->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); QVBoxLayout* vl = new QVBoxLayout; vl->addWidget(header); vl->addWidget(message); QHBoxLayout* displayMainLayout = new QHBoxLayout; displayMainLayout->addWidget(icon); displayMainLayout->addLayout(vl); displayWidget->setLayout(displayMainLayout); QHBoxLayout* containerLayout = new QHBoxLayout; containerLayout->addWidget(displayWidget); setLayout(containerLayout); show(); setMinimumHeight((int)(message->document()->size().height() *1.5 + header->height() +70)); timeout = new QTimer(this); connect(timeout, SIGNAL(timeout()), this, SLOT(fadeOut())); timeout->start(3000); }
//********************************************************************** void TulipApp::startTulip() { // adjust size if needed QRect sRect = QApplication::desktop()->availableGeometry(); QRect wRect(this->geometry()); QRect fRect(this->frameGeometry()); int deltaWidth = fRect.width() - wRect.width(); int deltaHeight = fRect.height() - wRect.height(); // adjust width if (fRect.width() > sRect.width()) { wRect.setWidth(sRect.width() - deltaWidth); } // screen width centering wRect.moveLeft(sRect.left() + (sRect.width() - wRect.width())/2); // adjust height if (fRect.height() > sRect.height()) { wRect.setHeight(sRect.height() - deltaHeight); } // screen height centering wRect.moveTop(sRect.top() + (deltaHeight - deltaWidth)/2 + (sRect.height() - wRect.height())/2); // adjust geometry this->setGeometry(wRect.x(), wRect.y(), wRect.width(), wRect.height()); UpdatePlugin::installWhenRestartTulip(); AppStartUp *appStart=new AppStartUp(this); QDialog *errorDlg; std::string errors; appStart->show(); appStart->initTulip(&pluginLoader,errors); //delete appStart; if (errors.size() > 0) { errorDlg = new QDialog(this); errorDlg->setWindowTitle("Errors when loading Tulip plugins !!!"); QVBoxLayout* errorDlgLayout = new QVBoxLayout(errorDlg); errorDlgLayout->setMargin(11); errorDlgLayout->setSpacing(6); QFrame *frame = new QFrame(errorDlg); QHBoxLayout* frameLayout = new QHBoxLayout(frame); frameLayout->setMargin(0); frameLayout->setSpacing(0); QSpacerItem* spacer = new QSpacerItem( 180, 20, QSizePolicy::Expanding, QSizePolicy::Minimum ); frameLayout->addItem( spacer ); QTextEdit* textWidget = new QTextEdit(QString(""),errorDlg); textWidget->setReadOnly(true); textWidget->setLineWrapMode(QTextEdit::NoWrap); errorDlgLayout->addWidget( textWidget ); QPushButton * closeB = new QPushButton( "Close", frame); frameLayout->addWidget( closeB ); errorDlgLayout->addWidget( frame ); QWidget::connect(closeB, SIGNAL(clicked()), errorDlg, SLOT(hide())); errorDlg->resize( QSize(400, 250).expandedTo(errorDlg->minimumSizeHint()) ); textWidget->setText(QString::fromUtf8(errors.c_str())); errorDlg->exec(); } if(ControllerFactory::factory->objMap.empty()) { QMessageBox::critical(this,tr("No controller found"),tr("No controller was found in Tulip plugins directory.\n Tulip cannot work without a controller.")); exit(-1); } buildMenus(); this->show(); enableElements(false); /*Load preference*/ PreferenceDialog::loadPreference(); OpenGlErrorViewer *oldErrorViewer=OpenGlConfigManager::getInst().setErrorViewer(new QtOpenGlErrorViewer); delete oldErrorViewer; if(PreferenceManager::getInst().getNetworkConnection()) { pluginsUpdateChecker = new PluginsUpdateChecker(pluginLoader.pluginsList,this); connect(pluginsUpdateChecker,SIGNAL(updateFinished()),this,SLOT(displayRestartForPlugins())); multiServerManager = pluginsUpdateChecker->getMultiServerManager(); } else { pluginsUpdateChecker=NULL; } /*QWidget *centralwidget = new QWidget(this); QGridLayout *gridLayout = new QGridLayout(centralwidget); tabWidget=new QTabWidget(centralwidget); centralwidget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred)); tabWidget->setGeometry(0,0,800,600); //tabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));*/ tabWidget->removeTab(0); connect(tabWidget,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int))); // set workspace background //newWorkspace->setBackground(QBrush(QPixmap(QString::fromUtf8(":/background_logo.png")))); aboutWidget=NULL; //======================================= //MDI //newWorkspace->setScrollBarsEnabled( true ); // Window Menu connect(windowsMenu, SIGNAL( aboutToShow() ), this, SLOT( windowsMenuAboutToShow() ) ); connect(windowsMenu, SIGNAL(triggered(QAction*)), this, SLOT( windowsMenuActivated(QAction*))); assistantProcess= new QProcess(this); std::string assistantPath(tlp::TulipLibDir); assistantPath += string("../"); #if defined(__linux__) assistantPath += string("bin"); // check if we are in a bundle if (QDir(assistantPath.c_str()).exists("assistant")) // assistant is in the bundle bin directory assistantProcessApp = QString::fromUtf8(assistantPath.c_str()) + "/assistant"; else // assistant is in the Qt binaries install directory assistantProcessApp = QLibraryInfo::location(QLibraryInfo::BinariesPath)+ "/assistant"; #else #if defined(_WIN32) assistantPath.append("bin/assistant.exe"); #else assistantPath.append("Assistant.app/Contents/MacOS/Assistant"); #endif assistantProcessApp = assistantPath.c_str(); #endif /*saveActions(menuBar(),NULL,controllerToMenu); saveActions(toolBar,NULL,controllerToToolBar);*/ tabIndexToController[-1]=NULL; saveInterface(-1); OpenGlErrorViewer *oldViewer=GlTextureManager::getInst().setErrorViewer(new QtOpenGlErrorViewer(this)); delete oldViewer; TemplateFactory<ControllerFactory, Controller, ControllerContext>::ObjectCreator::const_iterator it; it=ControllerFactory::factory->objMap.begin(); string name=(*it).first; ++it; if(it==ControllerFactory::factory->objMap.end()) { controllerAutoLoad=false; createController(name,newName()); currentTabIndex=0; Controller::currentActiveController(tabIndexToController[currentTabIndex]); controllerAutoLoad=true; } else { controllerAutoLoad=false; } int argc = qApp->argc(); if (argc>1) { char ** argv = qApp->argv(); for (int i=1; i<argc; ++i) { if(string(argv[i])=="--width") { int width = atoi(argv[i+1]); wRect.setWidth(width); ++i; continue; } if(string(argv[i])=="--height") { int height = atoi(argv[i+1]); wRect.setHeight(height); ++i; continue; } if(string(argv[i])=="--x") { int x = atoi(argv[i+1]); wRect.setX(x); ++i; continue; } if(string(argv[i])=="--y") { int y = atoi(argv[i+1]); wRect.setY(y); ++i; continue; } QFileInfo info(QString::fromUtf8(argv[i])); QString s = info.absoluteFilePath(); fileOpen(0, s); } } this->setGeometry(wRect.x(), wRect.y(),wRect.width(), wRect.height()); }
PmQuery::PmQuery(bool inputflag, bool printflag, bool noframeflag, bool nosliderflag, bool usesliderflag, bool exclusiveflag) : QDialog() { QHBoxLayout *hboxLayout; QVBoxLayout *vboxLayout; QSpacerItem *spacerItem; QSpacerItem *spacerItem1; QVBoxLayout *vboxLayout1; QHBoxLayout *hboxLayout1; QSpacerItem *spacerItem2; QString filename; if (iconic == HOST_ICON) filename = tr(":images/dialog-host.png"); else if (iconic == ERROR_ICON) filename = tr(":images/dialog-error.png"); else if (iconic == WARNING_ICON) filename = tr(":images/dialog-warning.png"); else if (iconic == ARCHIVE_ICON) filename = tr(":images/dialog-archive.png"); else if (iconic == QUESTION_ICON) filename = tr(":images/dialog-question.png"); else // (iconic == INFO_ICON) filename = tr(":images/dialog-information.png"); QIcon icon(filename); QPixmap pixmap(filename); setWindowIcon(icon); setWindowTitle(tr(title)); QGridLayout *gridLayout = new QGridLayout(this); gridLayout->setSpacing(6); gridLayout->setMargin(9); hboxLayout = new QHBoxLayout(); hboxLayout->setSpacing(6); hboxLayout->setMargin(0); vboxLayout = new QVBoxLayout(); vboxLayout->setSpacing(6); vboxLayout->setMargin(0); spacerItem = new QSpacerItem(20, 2, QSizePolicy::Minimum, QSizePolicy::Expanding); vboxLayout->addItem(spacerItem); QLabel *imageLabel = new QLabel(this); imageLabel->setPixmap(pixmap); vboxLayout->addWidget(imageLabel); spacerItem1 = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding); vboxLayout->addItem(spacerItem1); hboxLayout->addLayout(vboxLayout); vboxLayout1 = new QVBoxLayout(); vboxLayout1->setSpacing(6); vboxLayout1->setMargin(0); int height; int width = DEFAULT_EDIT_WIDTH; QLineEdit* lineEdit = NULL; QTextEdit* textEdit = NULL; if (inputflag && messagecount <= 1) { lineEdit = new QLineEdit(this); if (messagecount == 1) lineEdit->setText(tr(messages[0])); height = lineEdit->font().pointSize() + 4; if (height < 0) height = lineEdit->font().pixelSize() + 4; if (height < 0) height = lineEdit->heightForWidth(width) + 4; lineEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); lineEdit->setMinimumSize(QSize(width, height)); lineEdit->setGeometry(QRect(0, 0, width, height)); vboxLayout1->addWidget(lineEdit); } else { QFont fixed("monospace"); fixed.setStyleHint(QFont::TypeWriter); textEdit = new QTextEdit(this); textEdit->setFont(fixed); textEdit->setLineWrapMode(QTextEdit::FixedColumnWidth); textEdit->setLineWrapColumnOrWidth(80); textEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); if (nosliderflag) textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); else if (usesliderflag) textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); else textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); for (int m = 0; m < messagecount; m++) textEdit->append(tr(messages[m])); if (inputflag) textEdit->setReadOnly(false); else { textEdit->setLineWidth(1); textEdit->setFrameStyle(noframeflag ? QFrame::NoFrame : QFrame::Box | QFrame::Sunken); textEdit->setReadOnly(true); } if (usesliderflag) height = DEFAULT_EDIT_HEIGHT; else { height = textEdit->font().pointSize() + 4; if (height < 0) height = textEdit->font().pixelSize() + 4; if (height < 0) height = textEdit->heightForWidth(width) + 4; height *= messagecount; } textEdit->setMinimumSize(QSize(width, height)); textEdit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); textEdit->moveCursor(QTextCursor::Start); textEdit->ensureCursorVisible(); vboxLayout1->addWidget(textEdit); } hboxLayout1 = new QHBoxLayout(); hboxLayout1->setSpacing(6); hboxLayout1->setMargin(0); spacerItem2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum); hboxLayout1->addItem(spacerItem2); for (int i = 0; i < buttoncount; i++) { QueryButton *button = new QueryButton(printflag, this); button->setMinimumSize(QSize(72, 32)); button->setDefault(buttons[i] == defaultbutton); button->setQuery(this); button->setText(tr(buttons[i])); button->setStatus(statusi[i]); if (inputflag && buttons[i] == defaultbutton) { if (textEdit) button->setEditor(textEdit); else if (lineEdit) { button->setEditor(lineEdit); if (buttons[i] == defaultbutton) connect(lineEdit, SIGNAL(returnPressed()), button, SLOT(click())); } } connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked())); hboxLayout1->addWidget(button); } vboxLayout1->addLayout(hboxLayout1); hboxLayout->addLayout(vboxLayout1); gridLayout->addLayout(hboxLayout, 0, 0, 1, 1); gridLayout->setSizeConstraint(QLayout::SetFixedSize); if (inputflag && messagecount <= 1) resize(QSize(320, 83)); else resize(QSize(320, 132)); if (timeout) startTimer(timeout * 1000); if (exclusiveflag) setWindowModality(Qt::WindowModal); }
int main(int argc, char **argv) { Vals vals; /* the application */ QApplication app(argc, argv); app.setApplicationName(APP_NAME); app.setWindowIcon(QIcon(":/icon")); Window window; /* translations */ QTranslator qtr; if (qtr.load("qt_" + QLocale::system().name(), QTR_PATH)) app.installTranslator(&qtr); QTranslator htr; if (htr.load("H4KvT_" + QLocale::system().name(), ":/")) app.installTranslator(&htr); /* display information */ QTextEdit *text = new QTextEdit; text->setReadOnly(true); text->setLineWrapMode(QTextEdit::NoWrap); text->setToolTip(Window::tr("Drop any file for hashing")); QObject::connect(&window, &Window::idle, text, &QWidget::setEnabled); /* compare hash */ QLineEdit *test = new QLineEdit; HexVal hexval; test->setValidator(&hexval); test->installEventFilter(&window); test->setToolTip(Window::tr("Compare hashes")); QObject::connect(test, &QLineEdit::textChanged, [&](const QString &newValue) { if (vals.name != "") { std::string hashVal = newValue.toStdString(); std::transform(hashVal.begin(), hashVal.end(), hashVal.begin(), ::tolower); std::stringstream html; if (hashVal != "") html << "<style>.h" << hashVal << "{color:green}</style>"; html << "<div style='margin-bottom:2; font-size:27px'><i><b>" << vals.name << "</b></i></div>"; html << "<div style='margin-bottom:7; margin-left:23; font-size:13px'>" << vals.path << "</div>"; if (!ALL(vals,"")) { html << "<div style='font-size:13px'><table>"; if (vals.md5 != "") html << "<tr><td>md5: </td><td class='h" << vals.md5 << "'>" << vals.md5 << "</td</tr>"; if (vals.sha1 != "") html << "<tr><td>sha1: </td><td class='h" << vals.sha1 << "'>" << vals.sha1 << "</td</tr>"; if (vals.sha224 != "") html << "<tr><td>sha224: </td><td class='h" << vals.sha224 << "'>" << vals.sha224 << "</td</tr>"; if (vals.sha256 != "") html << "<tr><td>sha256: </td><td class='h" << vals.sha256 << "'>" << vals.sha256 << "</td</tr>"; if (vals.sha384 != "") html << "<tr><td>sha384: </td><td class='h" << vals.sha384 << "'>" << vals.sha384 << "</td</tr>"; if (vals.sha512 != "") html << "<tr><td>sha512: </td><td class='h" << vals.sha512 << "'>" << vals.sha512 << "</td</tr>"; html << "</table></div>"; } int horizontal = text->horizontalScrollBar()->value(); int vertical = text->verticalScrollBar()->value(); text->setHtml(QString::fromStdString(html.str())); text->horizontalScrollBar()->setValue(horizontal); text->verticalScrollBar()->setValue(vertical); test->setStyleSheet(ANY(vals,hashVal) ? "color:green" : ""); }}); /* error messages */ QLabel *error = new QLabel; error->setStyleSheet("color:red"); /* test or error */ QStackedWidget *stack = new QStackedWidget; delete stack->layout(); stack->setLayout(new Stack); stack->addWidget(error); stack->addWidget(test); stack->setCurrentIndex(1); /* toggle test or error */ QPushButton *hash = new QPushButton(QIcon(":/icon"), ""); hash->setCheckable(true); hash->setChecked(true); hash->setToolTip(Window::tr("Compare hashes")); QObject::connect(hash, &QPushButton::toggled, stack, &QStackedWidget::setCurrentIndex); /* store method */ QSettings settings("H4KvT", "H4KvT"); /* more methods */ bool more; try { settings.setValue("MoreHashingMethods", more = moreOrLess()); } catch (...) { more = settings.value("MoreHashingMethods", false).toBool(); } /* hashing method */ QComboBox *meth = new QComboBox; meth->addItem("md5"); meth->addItem("sha1"); if (more) meth->addItem("sha224"); meth->addItem("sha256"); if (more) meth->addItem("sha384"); meth->addItem("sha512"); meth->setToolTip(Window::tr("Hashing method")); meth->setCurrentText(settings.value("HashingMethod", "md5").toString()); QObject::connect(&window, &Window::idle, meth, &QWidget::setEnabled); QObject::connect(meth, &QComboBox::currentTextChanged, [&](const QString &text) { settings.setValue("HashingMethod", text); }); /* toolbar */ QHBoxLayout *pane = new QHBoxLayout; pane->addWidget(hash, 0, Qt::AlignLeft); pane->addWidget(stack); pane->addWidget(meth, 0, Qt::AlignRight); /* main layout */ QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(text); layout->addLayout(pane); /* the window */ window.centralWidget()->setLayout(layout); window.show(); /* future hashing */ QFutureWatcher<Vals> zu; QObject::connect(&zu, &QFutureWatcher<Vals>::finished, [&]() { Vals valsi = zu.future().result(); window.idle(true); if (valsi.path == "") { error->setText(QString::fromStdString(valsi.name)); hash->setChecked(false); } else { error->clear(); vals += valsi; test->textChanged(test->text()); } }); QObject::connect(meth, &QComboBox::currentTextChanged, [&](const QString &text) { if (vals.name != "") { window.idle(false); zu.setFuture(QtConcurrent::run(&update, text, vals)); }}); QObject::connect(&window, &Window::fileDroped, [&](const QString &name, const QString &path) { window.idle(false); zu.setFuture(QtConcurrent::run(&update, meth->currentText(), Vals(name, path))); }); /* hashing info */ QGraphicsBlurEffect blur; blur.setBlurHints(QGraphicsBlurEffect::AnimationHint); QPropertyAnimation anim(&blur, "blurRadius"); anim.setDuration(2000); anim.setLoopCount(-1); anim.setKeyValueAt(0, 0); anim.setKeyValueAt(0.5, 3); anim.setKeyValueAt(1, 0); QLabel *hashing = new QLabel; hashing->setPixmap(QPixmap(":/icon")); hashing->setAttribute(Qt::WA_TransparentForMouseEvents); hashing->setGraphicsEffect(&blur); hashing->hide(); (new QHBoxLayout(text))->addWidget(hashing, 0, Qt::AlignCenter); QObject::connect(&blur, &QGraphicsBlurEffect::blurRadiusChanged, hashing, static_cast<void(QWidget::*)()>(&QWidget::update)); QObject::connect(&window, &Window::idle, [&](bool idle) { if (idle) { hashing->hide(); anim.stop(); } else { hashing->show(); anim.start(); } }); /* about app */ QMenu about; QAction *action = about.addAction(QIcon(":/icon"), Window::tr("About %1").arg(APP_NAME)); action->setMenuRole(QAction::AboutRole); QObject::connect(action, &QAction::triggered, &window, &Window::about); error->setContextMenuPolicy(Qt::NoContextMenu); hash->setContextMenuPolicy(Qt::NoContextMenu); meth->setContextMenuPolicy(Qt::NoContextMenu); window.setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(&window, &QWidget::customContextMenuRequested, [&about, &window](const QPoint &pos) { about.popup(window.mapToGlobal(pos)); }); text->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(text, &QWidget::customContextMenuRequested, [action, text](const QPoint &pos) { if (QMenu *m = text->createStandardContextMenu()) { m->insertAction(m->insertSeparator(m->actions()[0]), action); m->popup(text->mapToGlobal(pos)); } }); test->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(test, &QWidget::customContextMenuRequested, [action, test](const QPoint &pos) { if (QMenu *m = test->createStandardContextMenu()) { m->insertAction(m->insertSeparator(m->actions()[0]), action); m->popup(test->mapToGlobal(pos)); } }); return app.exec(); }