diff --git a/examples/animation-dci/main.cpp b/examples/animation-dci/main.cpp index cc8a534c..b226cf09 100644 --- a/examples/animation-dci/main.cpp +++ b/examples/animation-dci/main.cpp @@ -16,9 +16,11 @@ #include #include #include - +#include #include #include +#include +#include DGUI_USE_NAMESPACE @@ -46,32 +48,42 @@ class IconWidget : public QMainWindow IconWidget(const QString &iconName) { setCentralWidget(label = new QLabel(this)); + label->setAcceptDrops(true); centralWidget()->setAttribute(Qt::WA_MouseTracking); centralWidget()->installEventFilter(this); statusBar()->addWidget(message = new QLabel()); auto normal = new QPushButton("Normal"); connect(normal, &QPushButton::clicked, this, [this] { - player.setMode(DDciIcon::Normal); + player.play(DDciIcon::Normal); }); auto hover = new QPushButton("Hover"); connect(hover, &QPushButton::clicked, this, [this] { - player.setMode(DDciIcon::Hover); + player.play(DDciIcon::Hover); }); auto pressed = new QPushButton("Pressed"); connect(pressed, &QPushButton::clicked, this, [this] { - player.setMode(DDciIcon::Pressed); + player.play(DDciIcon::Pressed); }); auto disabled = new QPushButton("Disabled"); connect(disabled, &QPushButton::clicked, this, [this] { - player.setMode(DDciIcon::Disabled); + player.play(DDciIcon::Disabled); }); + + auto open = new QPushButton("..."); + connect(open, &QPushButton::clicked, this, [this] { + QString dciFile = QFileDialog::getOpenFileName(this, "select a dci icon file", "", "*.dci"); + player.setIcon(DDciIcon(dciFile)); + player.play(DDciIcon::Normal); + }); + QWidget *menuWidget = new QWidget(this); QHBoxLayout *layout = new QHBoxLayout(menuWidget); layout->addWidget(normal); layout->addWidget(hover); layout->addWidget(pressed); layout->addWidget(disabled); + layout->addWidget(open); setMenuWidget(menuWidget); icon = DDciIcon::fromTheme(iconName); @@ -112,6 +124,20 @@ class IconWidget : public QMainWindow player.setMode(DDciIcon::Pressed); } else if (event->type() == QEvent::MouseButtonRelease) { player.setMode(label->hasMouseTracking() ? DDciIcon::Hover : DDciIcon::Normal); + } else if (event->type() == QEvent::DragEnter) { + event->accept(); + } else if (event->type() == QEvent::Drop) { + auto de = static_cast(event); + if (de->mimeData()->hasFormat("text/uri-list")) { + QString uris = de->mimeData()->data("text/uri-list"); + QUrl url(uris.split("\r\n").value(0)); + + DDciIcon icon(url.path()); + if (!icon.isNull()) { + player.setIcon(icon); + player.play(DDciIcon::Normal); + } + } } else { return false; }