mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
C++98 compatibility.
This commit is contained in:
parent
c74204d5b7
commit
08f1968b31
@ -14,17 +14,19 @@ windows {
|
||||
# MinGW
|
||||
*-g++* {
|
||||
QMAKE_CXXFLAGS += -std=c++11
|
||||
QMAKE_CXXFLAGS += -Wall -Wextra -pedantic
|
||||
}
|
||||
# MSVC
|
||||
*-msvc* {
|
||||
QMAKE_CXXFLAGS += /Za
|
||||
}
|
||||
}
|
||||
|
||||
SOURCES += \
|
||||
src/API.cpp \
|
||||
src/ContainerWidget.cpp \
|
||||
src/SectionWidget.cpp \
|
||||
src/SectionContent.cpp \
|
||||
src/ContainerWidget.cpp \
|
||||
src/SectionWidget.cpp \
|
||||
src/SectionContent.cpp \
|
||||
src/SectionTitleWidget.cpp \
|
||||
src/SectionContentWidget.cpp \
|
||||
src/DropOverlay.cpp \
|
||||
|
@ -72,4 +72,4 @@ public:
|
||||
};
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@ class FloatingWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
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();
|
||||
|
||||
InternalContentData takeContent();
|
||||
@ -41,4 +41,4 @@ private:
|
||||
};
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
|
@ -42,4 +42,4 @@ private:
|
||||
};
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
|
@ -22,4 +22,4 @@ private:
|
||||
};
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
|
@ -48,4 +48,4 @@ signals:
|
||||
};
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
|
@ -74,4 +74,4 @@ private:
|
||||
};
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
#endif
|
||||
#endif
|
||||
|
@ -83,4 +83,4 @@ QSplitter* findImmediateSplitter(class QWidget* w)
|
||||
return sp;
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
ADS_NAMESPACE_END
|
||||
|
@ -17,7 +17,7 @@ ADS_NAMESPACE_BEGIN
|
||||
|
||||
static QWidget* createDropWidget(const QString& img)
|
||||
{
|
||||
auto label = new QLabel();
|
||||
QLabel* label = new QLabel();
|
||||
label->setObjectName("DropAreaLabel");
|
||||
label->setPixmap(QPixmap(img));
|
||||
return label;
|
||||
@ -57,7 +57,7 @@ DropOverlay::~DropOverlay()
|
||||
|
||||
DropArea DropOverlay::cursorLocation() const
|
||||
{
|
||||
auto loc = InvalidDropArea;
|
||||
DropArea loc = InvalidDropArea;
|
||||
if (_splitAreas)
|
||||
{
|
||||
loc = _splitAreas->cursorLocation();
|
||||
@ -201,8 +201,8 @@ DropSplitAreas::DropSplitAreas(DropAreas areas, QWidget* parent) :
|
||||
|
||||
DropArea DropSplitAreas::cursorLocation() const
|
||||
{
|
||||
auto loc = InvalidDropArea;
|
||||
auto pos = mapFromGlobal(QCursor::pos());
|
||||
DropArea loc = InvalidDropArea;
|
||||
QPoint pos = mapFromGlobal(QCursor::pos());
|
||||
if (_top && _top->geometry().contains(pos))
|
||||
{
|
||||
loc = TopDropArea;
|
||||
|
@ -21,7 +21,7 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
|
||||
_titleWidget(titleWidget),
|
||||
_contentWidget(contentWidget)
|
||||
{
|
||||
auto l = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
l->setSpacing(0);
|
||||
setLayout(l);
|
||||
@ -38,7 +38,7 @@ FloatingWidget::FloatingWidget(ContainerWidget* container, SectionContent::RefPt
|
||||
// maximizeButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
// _titleLayout->addWidget(maximizeButton);
|
||||
|
||||
auto closeButton = new QPushButton();
|
||||
QPushButton* closeButton = new QPushButton();
|
||||
closeButton->setObjectName("closeButton");
|
||||
closeButton->setFlat(true);
|
||||
closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
|
||||
|
@ -53,4 +53,4 @@ SectionContent::RefPtr SectionContent::newSectionContent(QWidget* title, QWidget
|
||||
return sc;
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
ADS_NAMESPACE_END
|
||||
|
@ -8,11 +8,11 @@ SectionContentWidget::SectionContentWidget(SectionContent::RefPtr c, QWidget* pa
|
||||
QFrame(parent),
|
||||
_content(c)
|
||||
{
|
||||
auto l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
l->setSpacing(0);
|
||||
l->addWidget(_content->contentWidget());
|
||||
setLayout(l);
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
ADS_NAMESPACE_END
|
||||
|
@ -30,7 +30,7 @@ SectionTitleWidget::SectionTitleWidget(SectionContent::RefPtr content, QWidget*
|
||||
_tabMoving(false),
|
||||
_activeTab(false)
|
||||
{
|
||||
auto l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
l->addWidget(content->titleWidget());
|
||||
setLayout(l);
|
||||
}
|
||||
@ -74,33 +74,33 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||
// Drop contents of FloatingWidget into SectionWidget.
|
||||
if (_fw)
|
||||
{
|
||||
auto cw = findParentContainerWidget(this);
|
||||
auto sw = cw->sectionAt(cw->mapFromGlobal(ev->globalPos()));
|
||||
ContainerWidget* cw = findParentContainerWidget(this);
|
||||
SectionWidget* sw = cw->sectionAt(cw->mapFromGlobal(ev->globalPos()));
|
||||
if (sw)
|
||||
{
|
||||
auto loc = showDropOverlay(sw);
|
||||
DropArea loc = showDropOverlay(sw);
|
||||
if (loc != InvalidDropArea)
|
||||
{
|
||||
#if !defined(ADS_ANIMATIONS_ENABLED)
|
||||
auto data = _fw->takeContent();
|
||||
InternalContentData data = _fw->takeContent();
|
||||
_fw->deleteLater();
|
||||
_fw.clear();
|
||||
cw->dropContent(data, sw, loc);
|
||||
#else
|
||||
auto moveAnim = new QPropertyAnimation(_fw, "pos", this);
|
||||
QPropertyAnimation* moveAnim = new QPropertyAnimation(_fw, "pos", this);
|
||||
moveAnim->setStartValue(_fw->pos());
|
||||
moveAnim->setEndValue(sw->mapToGlobal(sw->rect().topLeft()));
|
||||
moveAnim->setDuration(ADS_ANIMATION_DURATION);
|
||||
|
||||
auto resizeAnim = new QPropertyAnimation(_fw, "size", this);
|
||||
QPropertyAnimation* resizeAnim = new QPropertyAnimation(_fw, "size", this);
|
||||
resizeAnim->setStartValue(_fw->size());
|
||||
resizeAnim->setEndValue(sw->size());
|
||||
resizeAnim->setDuration(ADS_ANIMATION_DURATION);
|
||||
|
||||
auto animGroup = new QParallelAnimationGroup(this);
|
||||
QParallelAnimationGroup* animGroup = new QParallelAnimationGroup(this);
|
||||
QObject::connect(animGroup, &QPropertyAnimation::finished, [this, data, sw, loc]()
|
||||
{
|
||||
auto data = _fw->takeContent();
|
||||
InternalContentData data = _fw->takeContent();
|
||||
_fw->deleteLater();
|
||||
_fw.clear();
|
||||
cw->dropContent(data, sw, loc);
|
||||
@ -127,7 +127,7 @@ void SectionTitleWidget::mouseReleaseEvent(QMouseEvent* ev)
|
||||
if (dropArea != DropArea::InvalidDropArea)
|
||||
{
|
||||
#if !defined(ADS_ANIMATIONS_ENABLED)
|
||||
auto data = _fw->takeContent();
|
||||
InternalContentData data = _fw->takeContent();
|
||||
_fw->deleteLater();
|
||||
_fw.clear();
|
||||
cw->dropContent(data, NULL, dropArea);
|
||||
@ -215,7 +215,7 @@ void SectionTitleWidget::mouseMoveEvent(QMouseEvent* ev)
|
||||
&& !section->titleAreaGeometry().contains(section->mapFromGlobal(ev->globalPos())))
|
||||
{
|
||||
// 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->resize(section->size());
|
||||
|
@ -31,7 +31,7 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
|
||||
_uid(NextUid++),
|
||||
_container(parent)
|
||||
{
|
||||
auto l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
l->setSpacing(0);
|
||||
setLayout(l);
|
||||
@ -48,7 +48,7 @@ SectionWidget::SectionWidget(ContainerWidget* parent) :
|
||||
l->addLayout(_contentsLayout, 1);
|
||||
|
||||
#if defined(ADS_ANIMATIONS_ENABLED)
|
||||
auto shadow = new QGraphicsDropShadowEffect(this);
|
||||
QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(this);
|
||||
shadow->setOffset(0, 0);
|
||||
shadow->setBlurRadius(8);
|
||||
setGraphicsEffect(shadow);
|
||||
@ -65,7 +65,7 @@ SectionWidget::~SectionWidget()
|
||||
_container->_sections.removeAll(this);
|
||||
|
||||
// Delete empty QSplitter.
|
||||
auto splitter = findParentSplitter(this);
|
||||
QSplitter* splitter = findParentSplitter(this);
|
||||
if (splitter && splitter->count() == 0)
|
||||
{
|
||||
splitter->deleteLater();
|
||||
@ -97,12 +97,12 @@ void SectionWidget::addContent(SectionContent::RefPtr c)
|
||||
{
|
||||
_contents.append(c);
|
||||
|
||||
auto title = new SectionTitleWidget(c, nullptr);
|
||||
SectionTitleWidget* title = new SectionTitleWidget(c, NULL);
|
||||
_sectionTitles.append(title);
|
||||
_tabsLayout->insertWidget(_tabsLayout->count() - 1, title);
|
||||
QObject::connect(title, &SectionTitleWidget::clicked, this, &SectionWidget::onSectionTitleClicked);
|
||||
|
||||
auto content = new SectionContentWidget(c, nullptr);
|
||||
SectionContentWidget* content = new SectionContentWidget(c, NULL);
|
||||
_sectionContents.append(content);
|
||||
_contentsLayout->addWidget(content);
|
||||
|
||||
@ -153,7 +153,7 @@ InternalContentData SectionWidget::take(int uid, bool del)
|
||||
}
|
||||
|
||||
// Title wrapper widget (TAB)
|
||||
auto title = _sectionTitles.takeAt(index);
|
||||
SectionTitleWidget* title = _sectionTitles.takeAt(index);
|
||||
if (title)
|
||||
{
|
||||
_tabsLayout->removeWidget(title);
|
||||
@ -163,7 +163,7 @@ InternalContentData SectionWidget::take(int uid, bool del)
|
||||
}
|
||||
|
||||
// Content wrapper widget (CONTENT)
|
||||
auto content = _sectionContents.takeAt(index);
|
||||
SectionContentWidget* content = _sectionContents.takeAt(index);
|
||||
if (content)
|
||||
{
|
||||
_contentsLayout->removeWidget(content);
|
||||
@ -240,10 +240,10 @@ void SectionWidget::setCurrentIndex(int index)
|
||||
qDebug() << Q_FUNC_INFO << index;
|
||||
for (int i = 0; i < _tabsLayout->count(); ++i)
|
||||
{
|
||||
auto item = _tabsLayout->itemAt(i);
|
||||
QLayoutItem* item = _tabsLayout->itemAt(i);
|
||||
if (item->widget())
|
||||
{
|
||||
auto stw = dynamic_cast<SectionTitleWidget*>(item->widget());
|
||||
SectionTitleWidget* stw = dynamic_cast<SectionTitleWidget*>(item->widget());
|
||||
if (i == index)
|
||||
stw->setActiveTab(true);
|
||||
else
|
||||
@ -266,12 +266,12 @@ void SectionWidget::paintEvent(QPaintEvent* e)
|
||||
|
||||
void SectionWidget::onSectionTitleClicked()
|
||||
{
|
||||
auto stw = qobject_cast<SectionTitleWidget*>(sender());
|
||||
SectionTitleWidget* stw = qobject_cast<SectionTitleWidget*>(sender());
|
||||
if (stw)
|
||||
{
|
||||
auto index = _tabsLayout->indexOf(stw);
|
||||
int index = _tabsLayout->indexOf(stw);
|
||||
setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
ADS_NAMESPACE_END
|
||||
ADS_NAMESPACE_END
|
||||
|
@ -9,27 +9,27 @@
|
||||
IconTitleWidget::IconTitleWidget(const QIcon& icon, const QString& title, QWidget *parent) :
|
||||
QFrame(parent)
|
||||
{
|
||||
auto l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
QBoxLayout* l = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
l->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(l);
|
||||
|
||||
// Icon label
|
||||
if (icon.isNull())
|
||||
{
|
||||
// auto titleIcon = new QLabel();
|
||||
// QLabel* titleIcon = new QLabel();
|
||||
// titleIcon->setPixmap(style()->standardIcon(QStyle::SP_MessageBoxInformation).pixmap(16, 16));
|
||||
// l->addWidget(titleIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto titleIcon = new QLabel();
|
||||
QLabel* titleIcon = new QLabel();
|
||||
titleIcon->setPixmap(icon.pixmap(16, 16));
|
||||
l->addWidget(titleIcon);
|
||||
}
|
||||
|
||||
// Title label
|
||||
auto titleText = new QLabel(title);
|
||||
auto titleFont = titleText->font();
|
||||
QLabel* titleText = new QLabel(title);
|
||||
QFont titleFont = titleText->font();
|
||||
titleFont.setBold(true);
|
||||
titleText->setFont(titleFont);
|
||||
l->addWidget(titleText, 1);
|
||||
|
@ -10,10 +10,10 @@ static void centerWidget(QWidget* widget)
|
||||
if (widget)
|
||||
{
|
||||
QDesktopWidget deskWidget;
|
||||
const auto screenIndex = deskWidget.primaryScreen();
|
||||
const auto deskRect = deskWidget.availableGeometry(screenIndex);
|
||||
const auto x = (deskRect.width() - widget->rect().width()) / 2;
|
||||
const auto y = (deskRect.height() - widget->rect().height()) / 2;
|
||||
const int screenIndex = deskWidget.primaryScreen();
|
||||
const QRect deskRect = deskWidget.availableGeometry(screenIndex);
|
||||
const int x = (deskRect.width() - widget->rect().width()) / 2;
|
||||
const int y = (deskRect.height() - widget->rect().height()) / 2;
|
||||
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)
|
||||
{
|
||||
QDesktopWidget deskWidget;
|
||||
const auto screenIndex = deskWidget.primaryScreen();
|
||||
const auto deskRect = deskWidget.availableGeometry(screenIndex);
|
||||
const auto w = (deskRect.width() / 100) * widthPC;
|
||||
const auto h = (deskRect.height() / 100) * heightPC;
|
||||
const int screenIndex = deskWidget.primaryScreen();
|
||||
const QRect deskRect = deskWidget.availableGeometry(screenIndex);
|
||||
const int w = (deskRect.width() / 100) * widthPC;
|
||||
const int h = (deskRect.height() / 100) * heightPC;
|
||||
widget->resize(w, h);
|
||||
}
|
||||
}
|
||||
|
@ -88,14 +88,17 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
section->addContent(createCalendarSC());
|
||||
_container->addSection(section);
|
||||
|
||||
QByteArray ba;
|
||||
QFile f("test.dat");
|
||||
if (f.open(QFile::ReadOnly))
|
||||
if (true)
|
||||
{
|
||||
ba = f.readAll();
|
||||
f.close();
|
||||
QByteArray ba;
|
||||
QFile f("test.dat");
|
||||
if (f.open(QFile::ReadOnly))
|
||||
{
|
||||
ba = f.readAll();
|
||||
f.close();
|
||||
}
|
||||
_container->restoreGeometry(ba);
|
||||
}
|
||||
_container->restoreGeometry(ba);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -118,6 +121,7 @@ void MainWindow::onActionAddSectionContentTriggered()
|
||||
|
||||
void MainWindow::contextMenuEvent(QContextMenuEvent* e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
QMenu* m = _container->createContextMenu();
|
||||
m->exec(QCursor::pos());
|
||||
delete m;
|
||||
@ -125,11 +129,15 @@ void MainWindow::contextMenuEvent(QContextMenuEvent* e)
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* e)
|
||||
{
|
||||
QByteArray ba = _container->saveGeometry();
|
||||
QFile f("test.dat");
|
||||
if (f.open(QFile::WriteOnly))
|
||||
Q_UNUSED(e);
|
||||
if (true)
|
||||
{
|
||||
f.write(ba);
|
||||
f.close();
|
||||
QByteArray ba = _container->saveGeometry();
|
||||
QFile f("test.dat");
|
||||
if (f.open(QFile::WriteOnly))
|
||||
{
|
||||
f.write(ba);
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user