void LinkSelectionItem::appear(const QPointF& animStartPos, const QRectF& linkRect) { QGraphicsBlurEffect* blur = new QGraphicsBlurEffect(); blur->setBlurHints(QGraphicsBlurEffect::PerformanceHint); blur->setBlurRadius(15); setGraphicsEffect(blur); QPropertyAnimation* rectAnimation = new QPropertyAnimation(this, "rect"); rectAnimation->setDuration(s_appearAnimDuration); rectAnimation->setStartValue(QRectF(animStartPos, QSize(3, 3))); rectAnimation->setEndValue(linkRect); rectAnimation->setEasingCurve(QEasingCurve::OutExpo); QPropertyAnimation* opacityAnimation = new QPropertyAnimation(this, "opacity"); opacityAnimation->setDuration(s_disappearAnimDuration); opacityAnimation->setStartValue(s_linkOpacity); opacityAnimation->setEndValue(0.0); opacityAnimation->setEasingCurve(QEasingCurve::InExpo); m_linkSelectiogroup.addAnimation(rectAnimation); m_linkSelectiogroup.addAnimation(opacityAnimation); m_linkSelectiogroup.start(); }
void AbstractContent::setFxIndex(int index) { if (m_fxIndex == index) return; m_fxIndex = index; // apply graphics effect #if QT_VERSION >= 0x040600 switch (m_fxIndex) { default: setGraphicsEffect(0); break; case 1: { QGraphicsDropShadowEffect * ds = new QGraphicsDropShadowEffect(this); ds->setColor(Qt::black); ds->setBlurRadius(7); ds->setOffset(1, 1); setGraphicsEffect(ds); } break; case 2: { QGraphicsDropShadowEffect * ds = new QGraphicsDropShadowEffect(this); ds->setColor(Qt::white); ds->setBlurRadius(7); ds->setOffset(1, 1); setGraphicsEffect(ds); } break; case 3: { QGraphicsBlurEffect * b = new QGraphicsBlurEffect(this); b->setBlurRadius(5); b->setBlurHints(QGraphicsBlurEffect::QualityHint); setGraphicsEffect(b); } break; case 4: { QGraphicsBlurEffect * b = new QGraphicsBlurEffect(this); b->setBlurRadius(16); b->setBlurHints(QGraphicsBlurEffect::QualityHint); setGraphicsEffect(b); } break; } #endif emit fxIndexChanged(); }
BlurItem::BlurItem(QGraphicsItem *parent) : QGraphicsRectItem(parent) { m_item = new QGraphicsPixmapItem(this); QGraphicsBlurEffect *blur = new QGraphicsBlurEffect(); blur->setBlurRadius(6); blur->setBlurHints(QGraphicsBlurEffect::PerformanceHint); m_item->setGraphicsEffect(blur); setFlag(ItemIsSelectable); }
QPixmap Icon::applyEffects() const { QPixmap gfx = pixmap; if (isColor && !qFuzzyIsNull(depth)) { QLabel w; QGraphicsColorizeEffect *effect = new QGraphicsColorizeEffect(); effect->setColor(color); effect->setStrength(depth); w.setPixmap(gfx); w.setGraphicsEffect(effect); gfx = w.grab(); } if (!qFuzzyIsNull(radius)) { QImage canvas(gfx.size(), QImage::Format_ARGB32_Premultiplied); QPainter painter(&canvas); painter.setCompositionMode(QPainter::CompositionMode_Source); painter.fillRect(gfx.rect(), Qt::transparent); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(gfx)); painter.setRenderHint(QPainter::Antialiasing); painter.drawRoundedRect(gfx.rect(), radius, radius); painter.end(); gfx = QPixmap::fromImage(canvas); } if (blur > 1.0) { QLabel w; QGraphicsBlurEffect *effect = new QGraphicsBlurEffect(); effect->setBlurRadius(blur); effect->setBlurHints(QGraphicsBlurEffect::QualityHint); w.setPixmap(gfx); w.setGraphicsEffect(effect); gfx = w.grab(); } if (flipX) { gfx = gfx.transformed(QTransform().scale(-1, 1)); } if (flipY) { gfx = gfx.transformed(QTransform().scale(1, -1)); } if (angle != 0) { gfx = gfx.transformed(QTransform().rotate(angle)); } return gfx; }
QGraphicsMapScene::QGraphicsMapScene(int id, QGraphicsView *view, QObject *parent) : QGraphicsScene(parent) { m_init = false; m_view = view; m_view->setMouseTracking(true); m_undoStack = new QUndoStack(this); m_selectionTile = new QGraphicsRectItem(QRectF(QRect(0,32,32,32))); m_selecting = false; for (unsigned int i = 1; i < Data::treemap.maps.size(); i++) if (Data::treemap.maps[i].ID == id) { n_mapInfo = Data::treemap.maps[i]; break; } m_eventMenu = new QMenu(m_view); QList<QAction*> actions; actions << new QAction(QIcon(":/icons/share/old_playtest.png"), "Start Game Here", this); actions << new QAction(QIcon(":/icons/share/old_edit.png"), "Set Start Position", this); actions << new QAction(QIcon(":/icons/share/old_event_layer.png"), "New Event", this); actions << new QAction(QIcon(":/icons/share/old_event_layer.png"), "Copy Event", this); actions << new QAction(QIcon(":/icons/share/old_event_layer.png"), "Cut Event", this); actions << new QAction(QIcon(":/icons/share/old_event_layer.png"), "Paste Event", this); actions << new QAction(QIcon(":/icons/share/old_event_layer.png"), "Delete Event", this); connect(actions[0],SIGNAL(triggered()),this,SLOT(on_actionRunHere())); connect(actions[1],SIGNAL(triggered()),this,SLOT(on_actionSetStartPosition())); connect(actions[2],SIGNAL(triggered()),this,SLOT(on_actionNewEvent())); connect(actions[6],SIGNAL(triggered()),this,SLOT(on_actionDeleteEvent())); m_eventMenu->addActions(actions); m_lowerpix = new QGraphicsPixmapItem(); m_upperpix = new QGraphicsPixmapItem(); addItem(m_lowerpix); addItem(m_upperpix); Load(); QPen selPen(Qt::yellow); selPen.setWidth(2); m_selectionTile->setPen(selPen); m_selectionTile->setVisible(false); this->addItem(m_selectionTile); m_drawing = false; m_cancelled = false; m_selecting = false; QGraphicsBlurEffect * effect = new QGraphicsBlurEffect(this); effect->setBlurRadius(2.0); effect->setBlurHints(QGraphicsBlurEffect::PerformanceHint); m_lowerpix->setGraphicsEffect(effect); m_upperpix->setGraphicsEffect(new QGraphicsOpacityEffect(this)); onLayerChanged(); onToolChanged(); }
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(); }