C++98 compatibility.

This commit is contained in:
mfreiholz 2016-02-12 07:15:10 +01:00
parent c74204d5b7
commit 08f1968b31
17 changed files with 77 additions and 67 deletions

View File

@ -14,17 +14,19 @@ windows {
# MinGW # MinGW
*-g++* { *-g++* {
QMAKE_CXXFLAGS += -std=c++11 QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -Wall -Wextra -pedantic
} }
# MSVC # MSVC
*-msvc* { *-msvc* {
QMAKE_CXXFLAGS += /Za
} }
} }
SOURCES += \ SOURCES += \
src/API.cpp \ src/API.cpp \
src/ContainerWidget.cpp \ src/ContainerWidget.cpp \
src/SectionWidget.cpp \ src/SectionWidget.cpp \
src/SectionContent.cpp \ src/SectionContent.cpp \
src/SectionTitleWidget.cpp \ src/SectionTitleWidget.cpp \
src/SectionContentWidget.cpp \ src/SectionContentWidget.cpp \
src/DropOverlay.cpp \ src/DropOverlay.cpp \

View File

@ -72,4 +72,4 @@ public:
}; };
ADS_NAMESPACE_END ADS_NAMESPACE_END
#endif #endif

View File

@ -22,7 +22,7 @@ class FloatingWidget : public QWidget
Q_OBJECT Q_OBJECT
public: public:
FloatingWidget(ContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent = nullptr); FloatingWidget(ContainerWidget* container, SectionContent::RefPtr sc, SectionTitleWidget* titleWidget, SectionContentWidget* contentWidget, QWidget* parent = NULL);
virtual ~FloatingWidget(); virtual ~FloatingWidget();
InternalContentData takeContent(); InternalContentData takeContent();
@ -41,4 +41,4 @@ private:
}; };
ADS_NAMESPACE_END ADS_NAMESPACE_END
#endif #endif

View File

@ -42,4 +42,4 @@ private:
}; };
ADS_NAMESPACE_END ADS_NAMESPACE_END
#endif #endif

View File

@ -22,4 +22,4 @@ private:
}; };
ADS_NAMESPACE_END ADS_NAMESPACE_END
#endif #endif

View File

@ -48,4 +48,4 @@ signals:
}; };
ADS_NAMESPACE_END ADS_NAMESPACE_END
#endif #endif

View File

@ -74,4 +74,4 @@ private:
}; };
ADS_NAMESPACE_END ADS_NAMESPACE_END
#endif #endif

View File

@ -83,4 +83,4 @@ QSplitter* findImmediateSplitter(class QWidget* w)
return sp; return sp;
} }
ADS_NAMESPACE_END ADS_NAMESPACE_END

View File

@ -17,7 +17,7 @@ ADS_NAMESPACE_BEGIN
static QWidget* createDropWidget(const QString& img) static QWidget* createDropWidget(const QString& img)
{ {
auto label = new QLabel(); QLabel* label = new QLabel();
label->setObjectName("DropAreaLabel"); label->setObjectName("DropAreaLabel");
label->setPixmap(QPixmap(img)); label->setPixmap(QPixmap(img));
return label; return label;
@ -57,7 +57,7 @@ DropOverlay::~DropOverlay()
DropArea DropOverlay::cursorLocation() const DropArea DropOverlay::cursorLocation() const
{ {
auto loc = InvalidDropArea; DropArea loc = InvalidDropArea;
if (_splitAreas) if (_splitAreas)
{ {
loc = _splitAreas->cursorLocation(); loc = _splitAreas->cursorLocation();
@ -201,8 +201,8 @@ DropSplitAreas::DropSplitAreas(DropAreas areas, QWidget* parent) :
DropArea DropSplitAreas::cursorLocation() const DropArea DropSplitAreas::cursorLocation() const
{ {
auto loc = InvalidDropArea; DropArea loc = InvalidDropArea;
auto pos = mapFromGlobal(QCursor::pos()); QPoint pos = mapFromGlobal(QCursor::pos());
if (_top && _top->geometry().contains(pos)) if (_top && _top->geometry().contains(pos))
{ {
loc = TopDropArea; loc = TopDropArea;

View File

@ -21,7 +21,7 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
_titleWidget(titleWidget), _titleWidget(titleWidget),
_contentWidget(contentWidget) _contentWidget(contentWidget)
{ {
auto l = new QBoxLayout(QBoxLayout::TopToBottom, this); QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom, this);
l->setContentsMargins(0, 0, 0, 0); l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0); l->setSpacing(0);
setLayout(l); setLayout(l);
@ -38,7 +38,7 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
// maximizeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // maximizeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// _titleLayout->addWidget(maximizeButton); // _titleLayout->addWidget(maximizeButton);
auto closeButton = new QPushButton(); QPushButton* closeButton = new QPushButton();
closeButton->setObjectName("closeButton"); closeButton->setObjectName("closeButton");
closeButton->setFlat(true); closeButton->setFlat(true);
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));

View File

@ -53,4 +53,4 @@ SectionContent::RefPtr SectionContent::newSectionContent(QWidget* title, QWidget
return sc; return sc;
} }
ADS_NAMESPACE_END ADS_NAMESPACE_END

View File

@ -8,11 +8,11 @@ SectionContentWidget::SectionContentWidget(SectionContent::RefPtr c, QWidget* pa
QFrame(parent), QFrame(parent),
_content(c) _content(c)
{ {
auto l = new QBoxLayout(QBoxLayout::TopToBottom); QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
l->setContentsMargins(0, 0, 0, 0); l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0); l->setSpacing(0);
l->addWidget(_content->contentWidget()); l->addWidget(_content->contentWidget());
setLayout(l); setLayout(l);
} }
ADS_NAMESPACE_END ADS_NAMESPACE_END

View File

@ -30,7 +30,7 @@ SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget*
_tabMoving(false), _tabMoving(false),
_activeTab(false) _activeTab(false)
{ {
auto l = new QBoxLayout(QBoxLayout::LeftToRight); QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight);
l->addWidget(content->titleWidget()); l->addWidget(content->titleWidget());
setLayout(l); setLayout(l);
} }
@ -74,33 +74,33 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
// Drop contents of FloatingWidget into SectionWidget. // Drop contents of FloatingWidget into SectionWidget.
if (_fw) if (_fw)
{ {
auto cw = findParentContainerWidget(this); ContainerWidget* cw = findParentContainerWidget(this);
auto sw = cw->sectionAt(cw->mapFromGlobal(ev->globalPos())); SectionWidget* sw = cw->sectionAt(cw->mapFromGlobal(ev->globalPos()));
if (sw) if (sw)
{ {
auto loc = showDropOverlay(sw); DropArea loc = showDropOverlay(sw);
if (loc != InvalidDropArea) if (loc != InvalidDropArea)
{ {
#if !defined(ADS_ANIMATIONS_ENABLED) #if !defined(ADS_ANIMATIONS_ENABLED)
auto data = _fw->takeContent(); InternalContentData data = _fw->takeContent();
_fw->deleteLater(); _fw->deleteLater();
_fw.clear(); _fw.clear();
cw->dropContent(data, sw, loc); cw->dropContent(data, sw, loc);
#else #else
auto moveAnim = new QPropertyAnimation(_fw, "pos", this); QPropertyAnimation* moveAnim = new QPropertyAnimation(_fw, "pos", this);
moveAnim->setStartValue(_fw->pos()); moveAnim->setStartValue(_fw->pos());
moveAnim->setEndValue(sw->mapToGlobal(sw->rect().topLeft())); moveAnim->setEndValue(sw->mapToGlobal(sw->rect().topLeft()));
moveAnim->setDuration(ADS_ANIMATION_DURATION); moveAnim->setDuration(ADS_ANIMATION_DURATION);
auto resizeAnim = new QPropertyAnimation(_fw, "size", this); QPropertyAnimation* resizeAnim = new QPropertyAnimation(_fw, "size", this);
resizeAnim->setStartValue(_fw->size()); resizeAnim->setStartValue(_fw->size());
resizeAnim->setEndValue(sw->size()); resizeAnim->setEndValue(sw->size());
resizeAnim->setDuration(ADS_ANIMATION_DURATION); resizeAnim->setDuration(ADS_ANIMATION_DURATION);
auto animGroup = new QParallelAnimationGroup(this); QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this);
QObject::connect(animGroup, &QPropertyAnimation::finished, [this, data, sw, loc]() QObject::connect(animGroup, &QPropertyAnimation::finished, [this, data, sw, loc]()
{ {
auto data = _fw->takeContent(); InternalContentData data = _fw->takeContent();
_fw->deleteLater(); _fw->deleteLater();
_fw.clear(); _fw.clear();
cw->dropContent(data, sw, loc); cw->dropContent(data, sw, loc);
@ -127,7 +127,7 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
if (dropArea != DropArea::InvalidDropArea) if (dropArea != DropArea::InvalidDropArea)
{ {
#if !defined(ADS_ANIMATIONS_ENABLED) #if !defined(ADS_ANIMATIONS_ENABLED)
auto data = _fw->takeContent(); InternalContentData data = _fw->takeContent();
_fw->deleteLater(); _fw->deleteLater();
_fw.clear(); _fw.clear();
cw->dropContent(data, NULL, dropArea); cw->dropContent(data, NULL, dropArea);
@ -215,7 +215,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
&& !section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPos()))) && !section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPos())))
{ {
// Create floating widget. // Create floating widget.
auto data = section->take(_content->uid(), false); InternalContentData data = section->take(_content->uid(), false);
_fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw); _fw = new FloatingWidget(cw, data.content, data.titleWidget, data.contentWidget, cw);
_fw->resize(section->size()); _fw->resize(section->size());

View File

@ -31,7 +31,7 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
_uid(NextUid++), _uid(NextUid++),
_container(parent) _container(parent)
{ {
auto l = new QBoxLayout(QBoxLayout::TopToBottom); QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
l->setContentsMargins(0, 0, 0, 0); l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0); l->setSpacing(0);
setLayout(l); setLayout(l);
@ -48,7 +48,7 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
l->addLayout(_contentsLayout, 1); l->addLayout(_contentsLayout, 1);
#if defined(ADS_ANIMATIONS_ENABLED) #if defined(ADS_ANIMATIONS_ENABLED)
auto shadow = new QGraphicsDropShadowEffect(this); QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this);
shadow->setOffset(0, 0); shadow->setOffset(0, 0);
shadow->setBlurRadius(8); shadow->setBlurRadius(8);
setGraphicsEffect(shadow); setGraphicsEffect(shadow);
@ -65,7 +65,7 @@ SectionWidget::~SectionWidget()
_container->_sections.removeAll(this); _container->_sections.removeAll(this);
// Delete empty QSplitter. // Delete empty QSplitter.
auto splitter = findParentSplitter(this); QSplitter* splitter = findParentSplitter(this);
if (splitter && splitter->count() == 0) if (splitter && splitter->count() == 0)
{ {
splitter->deleteLater(); splitter->deleteLater();
@ -97,12 +97,12 @@ void SectionWidget::addContent(SectionContent::RefPtr c)
{ {
_contents.append(c); _contents.append(c);
auto title = new SectionTitleWidget(c, nullptr); SectionTitleWidget* title = new SectionTitleWidget(c, NULL);
_sectionTitles.append(title); _sectionTitles.append(title);
_tabsLayout->insertWidget(_tabsLayout->count() - 1, title); _tabsLayout->insertWidget(_tabsLayout->count() - 1, title);
QObject::connect(title, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked); QObject::connect(title, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked);
auto content = new SectionContentWidget(c, nullptr); SectionContentWidget* content = new SectionContentWidget(c, NULL);
_sectionContents.append(content); _sectionContents.append(content);
_contentsLayout->addWidget(content); _contentsLayout->addWidget(content);
@ -153,7 +153,7 @@ InternalContentData SectionWidget::take(int uid, bool del)
} }
// Title wrapper widget (TAB) // Title wrapper widget (TAB)
auto title = _sectionTitles.takeAt(index); SectionTitleWidget* title = _sectionTitles.takeAt(index);
if (title) if (title)
{ {
_tabsLayout->removeWidget(title); _tabsLayout->removeWidget(title);
@ -163,7 +163,7 @@ InternalContentData SectionWidget::take(int uid, bool del)
} }
// Content wrapper widget (CONTENT) // Content wrapper widget (CONTENT)
auto content = _sectionContents.takeAt(index); SectionContentWidget* content = _sectionContents.takeAt(index);
if (content) if (content)
{ {
_contentsLayout->removeWidget(content); _contentsLayout->removeWidget(content);
@ -240,10 +240,10 @@ void SectionWidget::setCurrentIndex(int index)
qDebug() << Q_FUNC_INFO << index; qDebug() << Q_FUNC_INFO << index;
for (int i = 0; i < _tabsLayout->count(); ++i) for (int i = 0; i < _tabsLayout->count(); ++i)
{ {
auto item = _tabsLayout->itemAt(i); QLayoutItem* item = _tabsLayout->itemAt(i);
if (item->widget()) if (item->widget())
{ {
auto stw = dynamic_cast<SectionTitleWidget*>(item->widget()); SectionTitleWidget* stw = dynamic_cast<SectionTitleWidget*>(item->widget());
if (i == index) if (i == index)
stw->setActiveTab(true); stw->setActiveTab(true);
else else
@ -266,12 +266,12 @@ void SectionWidget::paintEvent(QPaintEvent* e)
void SectionWidget::onSectionTitleClicked() void SectionWidget::onSectionTitleClicked()
{ {
auto stw = qobject_cast<SectionTitleWidget*>(sender()); SectionTitleWidget* stw = qobject_cast<SectionTitleWidget*>(sender());
if (stw) if (stw)
{ {
auto index = _tabsLayout->indexOf(stw); int index = _tabsLayout->indexOf(stw);
setCurrentIndex(index); setCurrentIndex(index);
} }
} }
ADS_NAMESPACE_END ADS_NAMESPACE_END

View File

@ -9,27 +9,27 @@
IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent) : IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent) :
QFrame(parent) QFrame(parent)
{ {
auto l = new QBoxLayout(QBoxLayout::LeftToRight); QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight);
l->setContentsMargins(0, 0, 0, 0); l->setContentsMargins(0, 0, 0, 0);
setLayout(l); setLayout(l);
// Icon label // Icon label
if (icon.isNull()) if (icon.isNull())
{ {
// auto titleIcon = new QLabel(); // QLabel* titleIcon = new QLabel();
// titleIcon->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(16, 16)); // titleIcon->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(16, 16));
// l->addWidget(titleIcon); // l->addWidget(titleIcon);
} }
else else
{ {
auto titleIcon = new QLabel(); QLabel* titleIcon = new QLabel();
titleIcon->setPixmap(icon.pixmap(16, 16)); titleIcon->setPixmap(icon.pixmap(16, 16));
l->addWidget(titleIcon); l->addWidget(titleIcon);
} }
// Title label // Title label
auto titleText = new QLabel(title); QLabel* titleText = new QLabel(title);
auto titleFont = titleText->font(); QFont titleFont = titleText->font();
titleFont.setBold(true); titleFont.setBold(true);
titleText->setFont(titleFont); titleText->setFont(titleFont);
l->addWidget(titleText, 1); l->addWidget(titleText, 1);

View File

@ -10,10 +10,10 @@ static void centerWidget(QWidget* widget)
if (widget) if (widget)
{ {
QDesktopWidget deskWidget; QDesktopWidget deskWidget;
const auto screenIndex = deskWidget.primaryScreen(); const int screenIndex = deskWidget.primaryScreen();
const auto deskRect = deskWidget.availableGeometry(screenIndex); const QRect deskRect = deskWidget.availableGeometry(screenIndex);
const auto x = (deskRect.width() - widget->rect().width()) / 2; const int x = (deskRect.width() - widget->rect().width()) / 2;
const auto y = (deskRect.height() - widget->rect().height()) / 2; const int y = (deskRect.height() - widget->rect().height()) / 2;
widget->move(x, y); widget->move(x, y);
} }
} }
@ -23,10 +23,10 @@ static void resizeWidgetPerCent(QWidget* widget, qreal widthPC, qreal heightPC)
if (widget && widthPC >= 0.0 && heightPC >= 0.0) if (widget && widthPC >= 0.0 && heightPC >= 0.0)
{ {
QDesktopWidget deskWidget; QDesktopWidget deskWidget;
const auto screenIndex = deskWidget.primaryScreen(); const int screenIndex = deskWidget.primaryScreen();
const auto deskRect = deskWidget.availableGeometry(screenIndex); const QRect deskRect = deskWidget.availableGeometry(screenIndex);
const auto w = (deskRect.width() / 100) * widthPC; const int w = (deskRect.width() / 100) * widthPC;
const auto h = (deskRect.height() / 100) * heightPC; const int h = (deskRect.height() / 100) * heightPC;
widget->resize(w, h); widget->resize(w, h);
} }
} }

View File

@ -88,14 +88,17 @@ MainWindow::MainWindow(QWidget *parent) :
section->addContent(createCalendarSC()); section->addContent(createCalendarSC());
_container->addSection(section); _container->addSection(section);
QByteArray ba; if (true)
QFile f("test.dat");
if (f.open(QFile::ReadOnly))
{ {
ba = f.readAll(); QByteArray ba;
f.close(); QFile f("test.dat");
if (f.open(QFile::ReadOnly))
{
ba = f.readAll();
f.close();
}
_container->restoreGeometry(ba);
} }
_container->restoreGeometry(ba);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -118,6 +121,7 @@ void MainWindow::onActionAddSectionContentTriggered()
void MainWindow::contextMenuEvent(QContextMenuEvent* e) void MainWindow::contextMenuEvent(QContextMenuEvent* e)
{ {
Q_UNUSED(e);
QMenu* m = _container->createContextMenu(); QMenu* m = _container->createContextMenu();
m->exec(QCursor::pos()); m->exec(QCursor::pos());
delete m; delete m;
@ -125,11 +129,15 @@ void MainWindow::contextMenuEvent(QContextMenuEvent* e)
void MainWindow::closeEvent(QCloseEvent* e) void MainWindow::closeEvent(QCloseEvent* e)
{ {
QByteArray ba = _container->saveGeometry(); Q_UNUSED(e);
QFile f("test.dat"); if (true)
if (f.open(QFile::WriteOnly))
{ {
f.write(ba); QByteArray ba = _container->saveGeometry();
f.close(); QFile f("test.dat");
if (f.open(QFile::WriteOnly))
{
f.write(ba);
f.close();
}
} }
} }