summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGilles Caulier <[email protected]>2014-12-09 17:41:01 +0100
committerGilles Caulier <[email protected]>2014-12-09 17:41:01 +0100
commit38d1d3900b26362f6930d95f2f06363f2b1bb431 (patch)
tree171cd56e68d7fa04530235c6753d8de5e9f63595
parent0cd00051913267322a8d343098850b9dc273f7d2 (diff)
soem widgets to compose GUI quickly
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/rwidgetutils.cpp165
-rw-r--r--src/rwidgetutils.h101
3 files changed, 267 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 59c68f4..6079d10 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -19,6 +19,7 @@ set(kdcraw_LIB_SRCS kdcraw.cpp
rnuminput.cpp
rexpanderbox.cpp
rcombobox.cpp
+ rwidgetutils.cpp
dcrawsettingswidget.cpp
dcrawinfocontainer.cpp
rawdecodingsettings.cpp
diff --git a/src/rwidgetutils.cpp b/src/rwidgetutils.cpp
new file mode 100644
index 0000000..69a0605
--- /dev/null
+++ b/src/rwidgetutils.cpp
@@ -0,0 +1,165 @@
+/** ===========================================================
+ * @file
+ *
+ * This file is a part of digiKam project
+ * <a href="http://www.digikam.org">http://www.digikam.org</a>
+ *
+ * @date 2014-09-12
+ * @brief Simple widgets collection
+ *
+ * @author Copyright (C) 2014 by Gilles Caulier
+ * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#include "rwidgetutils.h"
+
+// Qt includes
+
+#include <QWidget>
+#include <QByteArray>
+#include <QBuffer>
+#include <QImage>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QApplication>
+
+namespace KDcrawIface
+{
+
+RActiveLabel::RActiveLabel(const QUrl& url, const QString& imgPath, QWidget* const parent)
+ : QLabel(parent)
+{
+ setTextFormat(Qt::RichText);
+ setTextInteractionFlags(Qt::TextBrowserInteraction);
+ setOpenExternalLinks(true);
+ QByteArray byteArray;
+ QBuffer buffer(&byteArray);
+ QImage img = QImage(imgPath);
+ img.save(&buffer, "PNG");
+ setText(QString::fromLatin1("<a href=\"%1\">%2</a>")
+ .arg(url.url())
+ .arg(QString::fromLatin1("<img src=\"data:image/png;base64,%1\">")
+ .arg(QString::fromLatin1(byteArray.toBase64().data()))));
+}
+
+RActiveLabel::~RActiveLabel()
+{
+}
+
+// ------------------------------------------------------------------------------------
+
+RHBox::RHBox(QWidget* const parent)
+ : QFrame(parent)
+{
+ QHBoxLayout* const layout = new QHBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setMargin(0);
+ setLayout(layout);
+}
+
+
+RHBox::RHBox(bool /*vertical*/, QWidget* const parent)
+ : QFrame(parent)
+{
+ QVBoxLayout* const layout = new QVBoxLayout(this);
+ layout->setSpacing(0);
+ layout->setMargin(0);
+ setLayout(layout);
+}
+
+RHBox::~RHBox()
+{
+}
+
+void RHBox::childEvent(QChildEvent* e)
+{
+ switch (e->type())
+ {
+ case QEvent::ChildAdded:
+ {
+ QChildEvent* const ce = static_cast<QChildEvent*>(e);
+
+ if (ce->child()->isWidgetType())
+ {
+ QWidget* const w = static_cast<QWidget*>(ce->child());
+ static_cast<QBoxLayout*>(layout())->addWidget(w);
+ }
+
+ break;
+ }
+
+ case QEvent::ChildRemoved:
+ {
+ QChildEvent* const ce = static_cast<QChildEvent*>(e);
+
+ if (ce->child()->isWidgetType())
+ {
+ QWidget* const w = static_cast<QWidget*>(ce->child());
+ static_cast<QBoxLayout*>(layout())->removeWidget(w);
+ }
+
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ QFrame::childEvent(e);
+}
+
+QSize RHBox::sizeHint() const
+{
+ RHBox* const b = const_cast<RHBox*>(this);
+ QApplication::sendPostedEvents(b, QEvent::ChildAdded);
+
+ return QFrame::sizeHint();
+}
+
+QSize RHBox::minimumSizeHint() const
+{
+ RHBox* const b = const_cast<RHBox*>(this);
+ QApplication::sendPostedEvents(b, QEvent::ChildAdded );
+
+ return QFrame::minimumSizeHint();
+}
+
+void RHBox::setSpacing(int spacing)
+{
+ layout()->setSpacing(spacing);
+}
+
+void RHBox::setMargin(int margin)
+{
+ layout()->setMargin(margin);
+}
+
+void RHBox::setStretchFactor(QWidget* const widget, int stretch)
+{
+ static_cast<QBoxLayout*>(layout())->setStretchFactor(widget, stretch);
+}
+
+// ------------------------------------------------------------------------------------
+
+RVBox::RVBox(QWidget* const parent)
+ : RHBox(true, parent)
+{
+}
+
+RVBox::~RVBox()
+{
+}
+
+} // namespace KDcrawIface
diff --git a/src/rwidgetutils.h b/src/rwidgetutils.h
new file mode 100644
index 0000000..40822f7
--- /dev/null
+++ b/src/rwidgetutils.h
@@ -0,0 +1,101 @@
+/** ===========================================================
+ * @file
+ *
+ * This file is a part of digiKam project
+ * <a href="http://www.digikam.org">http://www.digikam.org</a>
+ *
+ * @date 2014-09-12
+ * @brief Simple widgets collection
+ *
+ * @author Copyright (C) 2014 by Gilles Caulier
+ * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef RWIDGETUTILS_h
+#define RWIDGETUTILS_h
+
+// Qt includes
+
+#include <QLabel>
+#include <QUrl>
+#include <QString>
+#include <QFrame>
+
+// Local includes
+
+#include "libkdcraw_export.h"
+
+namespace KDcrawIface
+{
+
+/** A widget to host an image into a label with an active url which can be
+ * open to default web browser using simple mouse click.
+ */
+class LIBKDCRAW_EXPORT RActiveLabel : public QLabel
+{
+ Q_OBJECT
+
+public:
+
+ explicit RActiveLabel(const QUrl& url, const QString& imgPath, QWidget* const parent=0);
+ virtual ~RActiveLabel();
+};
+
+// ------------------------------------------------------------------------------------
+
+/** An Horizontal widget to host children widgets
+ */
+class LIBKDCRAW_EXPORT RHBox : public QFrame
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(RHBox)
+
+public:
+
+ explicit RHBox(QWidget* const parent=0);
+ virtual ~RHBox();
+
+ void setMargin(int margin);
+ void setSpacing(int space);
+ void setStretchFactor(QWidget* const widget, int stretch);
+
+ virtual QSize sizeHint() const;
+ virtual QSize minimumSizeHint() const;
+
+protected:
+
+ RHBox(bool vertical, QWidget* const parent);
+
+ virtual void childEvent(QChildEvent* e);
+};
+
+// ------------------------------------------------------------------------------------
+
+/** A Vertical widget to host children widgets
+ */
+class LIBKDCRAW_EXPORT RVBox : public RHBox
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(RVBox)
+
+ public:
+
+ explicit RVBox(QWidget* const parent=0);
+ virtual ~RVBox();
+};
+
+} // namespace KDcrawIface
+
+#endif // RWIDGETUTILS_h