Makes project mostly compatible with Qt 4.5

This commit is contained in:
mfreiholz 2016-02-12 08:00:31 +01:00
parent 08f1968b31
commit 8f13dbd77c
12 changed files with 106 additions and 16 deletions

View File

@ -18,7 +18,8 @@ windows {
} }
# MSVC # MSVC
*-msvc* { *-msvc* {
QMAKE_CXXFLAGS += /Za #QMAKE_CXXFLAGS += /Za
QMAKE_CXXFLAGS += /FS
} }
} }
@ -30,7 +31,8 @@ SOURCES += \
src/SectionTitleWidget.cpp \ src/SectionTitleWidget.cpp \
src/SectionContentWidget.cpp \ src/SectionContentWidget.cpp \
src/DropOverlay.cpp \ src/DropOverlay.cpp \
src/FloatingWidget.cpp src/FloatingWidget.cpp \
src/Internal.cpp
HEADERS += \ HEADERS += \
include/ads/API.h \ include/ads/API.h \
@ -40,7 +42,8 @@ HEADERS += \
include/ads/SectionTitleWidget.h \ include/ads/SectionTitleWidget.h \
include/ads/SectionContentWidget.h \ include/ads/SectionContentWidget.h \
include/ads/DropOverlay.h \ include/ads/DropOverlay.h \
include/ads/FloatingWidget.h include/ads/FloatingWidget.h \
include/ads/Internal.h
RESOURCES += \ RESOURCES += \
res/ads.qrc res/ads.qrc

View File

@ -37,15 +37,6 @@ enum DropArea
}; };
Q_DECLARE_FLAGS(DropAreas, DropArea) Q_DECLARE_FLAGS(DropAreas, DropArea)
class InternalContentData
{
public:
InternalContentData() : titleWidget(0), contentWidget(0) {}
QSharedPointer<class SectionContent> content;
class SectionTitleWidget* titleWidget;
class SectionContentWidget* contentWidget;
};
void deleteEmptySplitter(class ContainerWidget* container); void deleteEmptySplitter(class ContainerWidget* container);
class ContainerWidget* findParentContainerWidget(class QWidget* w); class ContainerWidget* findParentContainerWidget(class QWidget* w);
class SectionWidget* findParentSectionWidget(class QWidget* w); class SectionWidget* findParentSectionWidget(class QWidget* w);

View File

@ -16,6 +16,8 @@ class QMenu;
ADS_NAMESPACE_BEGIN ADS_NAMESPACE_BEGIN
class InternalContentData;
// ContainerWidget is the main container to provide the docking // ContainerWidget is the main container to provide the docking
// functionality. It manages mulitple Sections and all possible areas. // functionality. It manages mulitple Sections and all possible areas.
class ContainerWidget : public QFrame class ContainerWidget : public QFrame

View File

@ -14,6 +14,7 @@ ADS_NAMESPACE_BEGIN
class ContainerWidget; class ContainerWidget;
class SectionTitleWidget; class SectionTitleWidget;
class SectionContentWidget; class SectionContentWidget;
class InternalContentData;
// FloatingWidget holds and displays SectionContent as a floating window. // FloatingWidget holds and displays SectionContent as a floating window.
// It can be resized, moved and dropped back into a SectionWidget. // It can be resized, moved and dropped back into a SectionWidget.

View File

@ -0,0 +1,26 @@
#ifndef ADS_INTERNAL_HEADER
#define ADS_INTERNAL_HEADER
#include "ads/API.h"
#include "ads/SectionContent.h"
ADS_NAMESPACE_BEGIN
class SectionContent;
class SectionTitleWidget;
class SectionContentWidget;
class InternalContentData
{
public:
InternalContentData();
~InternalContentData();
SectionContent::RefPtr content;
SectionTitleWidget* titleWidget;
SectionContentWidget* contentWidget;
};
ADS_NAMESPACE_END
#endif

View File

@ -17,6 +17,7 @@ ADS_NAMESPACE_BEGIN
class ContainerWidget; class ContainerWidget;
class SectionTitleWidget; class SectionTitleWidget;
class SectionContentWidget; class SectionContentWidget;
class InternalContentData;
// SectionWidget manages multiple instances of SectionContent. // SectionWidget manages multiple instances of SectionContent.
// It displays a title TAB, which is clickable and will switch to // It displays a title TAB, which is clickable and will switch to

View File

@ -1,4 +1,5 @@
#include "ads/ContainerWidget.h" #include "ads/ContainerWidget.h"
#include "ads/Internal.h"
#include <QPaintEvent> #include <QPaintEvent>
#include <QPainter> #include <QPainter>
@ -40,17 +41,33 @@ static void dropContentOuterHelper(ContainerWidget* cw, QLayout* l, const Intern
QSplitter* sp = newSplitter(orientation); QSplitter* sp = newSplitter(orientation);
if (append) if (append)
{ {
#if QT_VERSION >= 0x050000
QLayoutItem* li = l->replaceWidget(oldsp, sp); QLayoutItem* li = l->replaceWidget(oldsp, sp);
sp->addWidget(oldsp); sp->addWidget(oldsp);
sp->addWidget(sw); sp->addWidget(sw);
delete li; delete li;
#else
int index = l->indexOf(oldsp);
QLayoutItem* li = l->takeAt(index);
sp->addWidget(oldsp);
sp->addWidget(sw);
delete li;
#endif
} }
else else
{ {
#if QT_VERSION >= 0x050000
sp->addWidget(sw); sp->addWidget(sw);
QLayoutItem* li = l->replaceWidget(oldsp, sp); QLayoutItem* li = l->replaceWidget(oldsp, sp);
sp->addWidget(oldsp); sp->addWidget(oldsp);
delete li; delete li;
#else
sp->addWidget(sw);
int index = l->indexOf(oldsp);
QLayoutItem* li = l->takeAt(index);
sp->addWidget(oldsp);
delete li;
#endif
} }
} }
} }
@ -349,7 +366,11 @@ QMenu* ContainerWidget::createContextMenu() const
QAction* a = m->addAction(QIcon(), QString("Floating %1").arg(c->uid())); QAction* a = m->addAction(QIcon(), QString("Floating %1").arg(c->uid()));
a->setCheckable(true); a->setCheckable(true);
a->setChecked(fw->isVisible()); a->setChecked(fw->isVisible());
#if QT_VERSION >= 0x050000
QObject::connect(a, &QAction::toggled, fw, &FloatingWidget::setVisible); QObject::connect(a, &QAction::toggled, fw, &FloatingWidget::setVisible);
#else
QObject::connect(a, SIGNAL(toggled(bool)), fw, SLOT(setVisible(bool)));
#endif
} }
} }

View File

@ -8,8 +8,8 @@
#include <QPainter> #include <QPainter>
#include <QGridLayout> #include <QGridLayout>
#include <QCursor> #include <QCursor>
#include <QtGui/QIcon> #include <QIcon>
#include <QtWidgets/QLabel> #include <QLabel>
ADS_NAMESPACE_BEGIN ADS_NAMESPACE_BEGIN
@ -288,7 +288,11 @@ void hideDropOverlay()
{ {
MyOverlay->hide(); MyOverlay->hide();
delete MyOverlay; delete MyOverlay;
#if QT_VERSION >= 0x050000
MyOverlayParent.clear(); MyOverlayParent.clear();
#else
MyOverlayParent = 0;
#endif
MyOverlayParentRect = QRect(); MyOverlayParentRect = QRect();
MyOverlayLastLocation = InvalidDropArea; MyOverlayLastLocation = InvalidDropArea;
} }

View File

@ -11,6 +11,7 @@
#include "ads/ContainerWidget.h" #include "ads/ContainerWidget.h"
#include "ads/SectionTitleWidget.h" #include "ads/SectionTitleWidget.h"
#include "ads/SectionContentWidget.h" #include "ads/SectionContentWidget.h"
#include "ads/Internal.h"
ADS_NAMESPACE_BEGIN ADS_NAMESPACE_BEGIN
@ -45,7 +46,8 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
closeButton->setToolTip(tr("Close")); closeButton->setToolTip(tr("Close"));
closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); closeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_titleLayout->addWidget(closeButton); _titleLayout->addWidget(closeButton);
QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::close); //QObject::connect(closeButton, &QPushButton::clicked, this, &FloatingWidget::close);
QObject::connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
// Content // Content
l->addWidget(contentWidget, 1); l->addWidget(contentWidget, 1);

View File

@ -0,0 +1,15 @@
#include "ads/Internal.h"
ADS_NAMESPACE_BEGIN
InternalContentData::InternalContentData() :
titleWidget(NULL),
contentWidget(NULL)
{
}
InternalContentData::~InternalContentData()
{
}
ADS_NAMESPACE_END

View File

@ -16,6 +16,7 @@
#include <QParallelAnimationGroup> #include <QParallelAnimationGroup>
#endif #endif
#include "ads/Internal.h"
#include "ads/DropOverlay.h" #include "ads/DropOverlay.h"
#include "ads/SectionContent.h" #include "ads/SectionContent.h"
#include "ads/SectionWidget.h" #include "ads/SectionWidget.h"
@ -84,7 +85,11 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
#if !defined(ADS_ANIMATIONS_ENABLED) #if !defined(ADS_ANIMATIONS_ENABLED)
InternalContentData data = _fw->takeContent(); InternalContentData data = _fw->takeContent();
_fw->deleteLater(); _fw->deleteLater();
#if QT_VERSION >= 0x050000
_fw.clear(); _fw.clear();
#else
_fw = 0;
#endif
cw->dropContent(data, sw, loc); cw->dropContent(data, sw, loc);
#else #else
QPropertyAnimation* moveAnim = new QPropertyAnimation(_fw, "pos", this); QPropertyAnimation* moveAnim = new QPropertyAnimation(_fw, "pos", this);
@ -129,7 +134,11 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
#if !defined(ADS_ANIMATIONS_ENABLED) #if !defined(ADS_ANIMATIONS_ENABLED)
InternalContentData data = _fw->takeContent(); InternalContentData data = _fw->takeContent();
_fw->deleteLater(); _fw->deleteLater();
#if QT_VERSION >= 0x050000
_fw.clear(); _fw.clear();
#else
_fw = 0;
#endif
cw->dropContent(data, NULL, dropArea); cw->dropContent(data, NULL, dropArea);
#else #else
#endif #endif

View File

@ -8,12 +8,13 @@
#include <QMimeData> #include <QMimeData>
#include <QPainter> #include <QPainter>
#include <QStyle> #include <QStyle>
#include <QtWidgets/QSplitter> #include <QSplitter>
#if defined(ADS_ANIMATIONS_ENABLED) #if defined(ADS_ANIMATIONS_ENABLED)
#include <QGraphicsDropShadowEffect> #include <QGraphicsDropShadowEffect>
#endif #endif
#include "ads/Internal.h"
#include "ads/DropOverlay.h" #include "ads/DropOverlay.h"
#include "ads/SectionContent.h" #include "ads/SectionContent.h"
#include "ads/SectionTitleWidget.h" #include "ads/SectionTitleWidget.h"
@ -100,7 +101,11 @@ void SectionWidget::addContent(SectionContent::RefPtr c)
SectionTitleWidget* title = new SectionTitleWidget(c, NULL); SectionTitleWidget* title = new SectionTitleWidget(c, NULL);
_sectionTitles.append(title); _sectionTitles.append(title);
_tabsLayout->insertWidget(_tabsLayout->count() - 1, title); _tabsLayout->insertWidget(_tabsLayout->count() - 1, title);
#if QT_VERSION >= 0x050000
QObject::connect(title, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked); QObject::connect(title, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked);
#else
QObject::connect(title, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
#endif
SectionContentWidget* content = new SectionContentWidget(c, NULL); SectionContentWidget* content = new SectionContentWidget(c, NULL);
_sectionContents.append(content); _sectionContents.append(content);
@ -120,7 +125,11 @@ void SectionWidget::addContent(const InternalContentData& data, bool autoActivat
_sectionTitles.append(data.titleWidget); _sectionTitles.append(data.titleWidget);
_tabsLayout->insertWidget(_tabsLayout->count() - 1, data.titleWidget); _tabsLayout->insertWidget(_tabsLayout->count() - 1, data.titleWidget);
#if QT_VERSION >= 0x050000
QObject::connect(data.titleWidget, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked); QObject::connect(data.titleWidget, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked);
#else
QObject::connect(data.titleWidget, SIGNAL(clicked()), this, SLOT(onSectionTitleClicked()));
#endif
_sectionContents.append(data.contentWidget); _sectionContents.append(data.contentWidget);
_contentsLayout->addWidget(data.contentWidget); _contentsLayout->addWidget(data.contentWidget);
@ -227,7 +236,13 @@ void SectionWidget::moveContent(int from, int to)
QLayoutItem* liFrom = NULL; QLayoutItem* liFrom = NULL;
liFrom = _tabsLayout->takeAt(from); liFrom = _tabsLayout->takeAt(from);
#if QT_VERSION >= 0x050000
_tabsLayout->insertItem(to, liFrom); _tabsLayout->insertItem(to, liFrom);
#else
_tabsLayout->insertWidget(to, liFrom->widget());
delete liFrom;
liFrom = NULL;
#endif
liFrom = _contentsLayout->takeAt(from); liFrom = _contentsLayout->takeAt(from);
_contentsLayout->insertWidget(to, liFrom->widget()); _contentsLayout->insertWidget(to, liFrom->widget());