Fix HtmlDelegate and move it to its own file. Also get rid of X11 on
authorPaulo Lieuthier <paulolieuthier@gmail.com>
Mon, 3 Nov 2014 18:36:07 +0000 (15:36 -0300)
committerPaulo Lieuthier <paulolieuthier@gmail.com>
Mon, 3 Nov 2014 18:36:07 +0000 (15:36 -0300)
CMakeLists.txt.

CMakeLists.txt
addplugindialog/lxqtaddplugindialog.cpp
lxqthtmldelegate.cpp [new file with mode: 0644]
lxqthtmldelegate.h [new file with mode: 0644]

index 3830521..936a9df 100644 (file)
@@ -13,6 +13,7 @@ set(LXQT_PKG_CONFIG_DESCRIPTION "Shared library for LXQt applications")
 set(PUB_HDRS
     aboutdialog/lxqtaboutdialog.h
     addplugindialog/lxqtaddplugindialog.h
+    lxqthtmldelegate.h
     lxqtsettings.h
     lxqtplugininfo.h
     lxqtpowermanager.h
@@ -34,6 +35,7 @@ set(PUB_HDRS
 
 set(PUBLIC_CLASSES
     AboutDialog
+    HtmlDelegate
     Settings
     PluginInfo
     PowerManager
@@ -62,6 +64,7 @@ set(PRIV_HDRS
 set(SRCS
     aboutdialog/lxqtaboutdialog.cpp
     aboutdialog/technicalinfo.cpp
+    lxqthtmldelegate.cpp
     lxqtplugininfo.cpp
     lxqtpowermanager.cpp
     addplugindialog/lxqtaddplugindialog.cpp
@@ -87,6 +90,7 @@ set(MOCS
     aboutdialog/lxqtaboutdialog.h
     aboutdialog/lxqtaboutdialog_p.h
     addplugindialog/lxqtaddplugindialog.h
+    lxqthtmldelegate.h
     lxqtpowermanager.h
     lxqtsettings.h
     lxqtscreensaver.h
@@ -152,12 +156,7 @@ set(LXQT_PKG_CONFIG_REQUIRES "Qt5Widgets Qt5Xml Qt5DBus Qt5X11Extras")
 
 include(${QTXDG_USE_FILE})
 
-find_package(X11 REQUIRED QUIET)
-
 include_directories(
-    "${CMAKE_CURRENT_SOURCE_DIR}"
-    "${CMAKE_CURRENT_BINARY_DIR}"
-    "${X11_INCLUDE_DIR}"
     "${QTXDG_INCLUDE_DIRS}"
 )
 
@@ -292,7 +291,6 @@ add_library(${LXQT_LIBRARY_NAME}
 
 qt5_use_modules(${LXQT_LIBRARY_NAME} Widgets DBus X11Extras)
 target_link_libraries(${LXQT_LIBRARY_NAME}
-    ${X11_X11_LIB}
     ${QTXDG_LIBRARIES}
 )
 
index c4f3b2a..ac9e943 100644 (file)
 
 #include "lxqtaddplugindialog.h"
 #include "ui_lxqtaddplugindialog.h"
-#include <QStyledItemDelegate>
-#include <QPainter>
+#include "lxqthtmldelegate.h"
 #include <QDebug>
-#include <QTextBrowser>
-#include <QAbstractTextDocumentLayout>
 #include <QLineEdit>
-
 #include <XdgIcon>
 #include <QListWidgetItem>
-#include <QItemDelegate>
-#include <QTextDocument>
 #include <QIcon>
-#include <QDebug>
 
 #include "lxqttranslator.h"
 
@@ -48,87 +41,6 @@ using namespace LxQt;
 #define SEARCH_ROLE  Qt::UserRole
 #define INDEX_ROLE   SEARCH_ROLE+1
 
-class HtmlDelegate : public QStyledItemDelegate
-{
-public:
-    HtmlDelegate(const QSize iconSize, QObject* parent = 0):
-        QStyledItemDelegate(parent),
-        mIconSize(iconSize)
-    {}
-    void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
-    virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
-private:
-    QSize mIconSize;
-};
-
-
-/************************************************
-
- ************************************************/
-void HtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
-{
-    if (!index.isValid())
-        return;
-
-    QStyleOptionViewItemV4 options = option;
-    initStyleOption(&options, index);
-
-    painter->save();
-
-    QTextDocument doc;
-    doc.setHtml(options.text);
-    QIcon icon = options.icon;
-
-    options.text = "";
-    options.icon = QIcon();
-    options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
-
-    // Draw icon ................................
-    QSize iconSize = icon.actualSize(mIconSize);
-    painter->translate(options.rect.left(), options.rect.top());
-    QRect iconRect = QRect(4, 4, iconSize.width(), iconSize.height());
-
-    icon.paint(painter, iconRect);
-
-    doc.setTextWidth(options.rect.width() - iconRect.right() - 10);
-
-    // shift text right to make icon visible
-    painter->translate(iconRect.right() + 8, 0);
-    QRect clip(0, 0, options.rect.width()-iconRect.right()- 10, options.rect.height());
-
-
-    painter->setClipRect(clip);
-    QAbstractTextDocumentLayout::PaintContext ctx;
-    // set text color to red for selected item
-    if (option.state & QStyle::State_Selected)
-    {
-        ctx.palette.setColor(QPalette::Text, option.palette.color(QPalette::HighlightedText));
-    }
-    ctx.clip = clip;
-    doc.documentLayout()->draw(painter, ctx);
-
-    painter->restore();
-}
-
-
-/************************************************
-
- ************************************************/
-QSize HtmlDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
-{
-    QStyleOptionViewItemV4 options = option;
-    initStyleOption(&options, index);
-
-    QSize iconSize = QIcon().actualSize(mIconSize);
-    QRect iconRect = QRect(4, 4, iconSize.width(), iconSize.height());
-
-    QTextDocument doc;
-    doc.setHtml(options.text);
-    doc.setTextWidth(options.rect.width()-iconRect.right()- 10);
-    return QSize(doc.idealWidth(), doc.size().height() + 8);
-}
-
-
 /************************************************
 
  ************************************************/
diff --git a/lxqthtmldelegate.cpp b/lxqthtmldelegate.cpp
new file mode 100644 (file)
index 0000000..e5e07bd
--- /dev/null
@@ -0,0 +1,114 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * LXQt - a lightweight, Qt based, desktop toolset
+ * http://lxqt.org
+ *
+ * Copyright: 2010-2011 Razor team
+ * Authors:
+ *   Alexander Sokoloff <sokoloff.a@gmail.com>
+ *   Paulo Lieuthier <paulolieuthier@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#include "lxqthtmldelegate.h"
+#include <QAbstractTextDocumentLayout>
+#include <QTextDocument>
+
+using namespace LxQt;
+
+
+HtmlDelegate::HtmlDelegate(const QSize iconSize, QObject* parent) :
+    QStyledItemDelegate(parent),
+    mIconSize(iconSize)
+{
+}
+
+HtmlDelegate::~HtmlDelegate()
+{
+}
+
+/************************************************
+
+ ************************************************/
+void HtmlDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+    if (!index.isValid())
+        return;
+
+    QStyleOptionViewItemV4 options = option;
+    initStyleOption(&options, index);
+
+    painter->save();
+
+    QTextDocument doc;
+    doc.setHtml(options.text);
+    QIcon icon = options.icon;
+
+    options.text = "";
+    options.icon = QIcon();
+
+    // icon size
+    QSize iconSize = icon.actualSize(mIconSize);
+    QRect iconRect = QRect(8, 8, iconSize.width(), iconSize.height());
+
+    // set doc size
+    doc.setTextWidth(options.rect.width() - iconRect.right() - 8);
+
+    options.widget->style()->drawControl(QStyle::CE_ItemViewItem, &options, painter);
+
+    // paint icon
+    painter->translate(options.rect.left(), options.rect.top());
+    icon.paint(painter, iconRect);
+
+    // shift text right to make icon visible
+    painter->translate(iconRect.right() + 8, 0);
+    QRect clip(0, 0, options.rect.width() - iconRect.right() - 8, options.rect.height());
+    painter->setClipRect(clip);
+
+    // set text color to red for selected item
+    QAbstractTextDocumentLayout::PaintContext ctx;
+    if (option.state & QStyle::State_Selected)
+    {
+        QPalette::ColorGroup colorGroup = (option.state & QStyle::State_Active) ? QPalette::Active : QPalette::Inactive;
+        ctx.palette.setColor(QPalette::Text, option.palette.color(colorGroup, QPalette::HighlightedText));
+    }
+
+    ctx.clip = clip;
+    doc.documentLayout()->draw(painter, ctx);
+
+    painter->restore();
+}
+
+
+/************************************************
+
+ ************************************************/
+QSize HtmlDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
+{
+    QStyleOptionViewItemV4 options = option;
+    initStyleOption(&options, index);
+
+    QSize iconSize = options.icon.actualSize(mIconSize);
+    QRect iconRect = QRect(8, 8, iconSize.width(), iconSize.height());
+
+    QTextDocument doc;
+    doc.setHtml(options.text);
+    doc.setTextWidth(options.rect.width() - iconRect.right() - 8);
+    return QSize(options.rect.width(), doc.size().height() + 8);
+}
diff --git a/lxqthtmldelegate.h b/lxqthtmldelegate.h
new file mode 100644 (file)
index 0000000..35f40e4
--- /dev/null
@@ -0,0 +1,57 @@
+/* BEGIN_COMMON_COPYRIGHT_HEADER
+ * (c)LGPL2+
+ *
+ * LXQt - a lightweight, Qt based, desktop toolset
+ * http://lxqt.org
+ *
+ * Copyright: 2010-2011 Razor team
+ * Authors:
+ *   Alexander Sokoloff <sokoloff.a@gmail.com>
+ *   Paulo Lieuthier <paulolieuthier@gmail.com>
+ *
+ * This program or library is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ *
+ * END_COMMON_COPYRIGHT_HEADER */
+
+#ifndef LXQTHTMLDELEGATE_H
+#define LXQTHTMLDELEGATE_H
+
+#include <QStyledItemDelegate>
+#include <QPainter>
+#include "lxqtglobals.h"
+
+namespace LxQt
+{
+
+class LXQT_API HtmlDelegate : public QStyledItemDelegate
+{
+    Q_OBJECT
+
+public:
+    explicit HtmlDelegate(const QSize iconSize, QObject* parent = 0);
+    virtual ~HtmlDelegate();
+
+    virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
+    virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
+
+private:
+    QSize mIconSize;
+};
+
+}
+
+#endif