1
0
mirror of https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git synced 2025-03-31 18:32:38 +08:00

Fixed placing of drop overlay cross, resizing of floating widget to drop

area rectangle size prior to insertion
This commit is contained in:
Uwe Kindler 2017-04-11 23:26:33 +02:00
parent 051c379e4a
commit bc37a2788e
8 changed files with 970 additions and 895 deletions

View File

@ -34,6 +34,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/QtAdvancedDockingSystem/demo}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/QtAdvancedDockingSystem/demo}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${QTDIR}/include&quot;"/> <listOptionValue builtIn="false" value="&quot;${QTDIR}/include&quot;"/>
</option> </option>
<option id="gnu.cpp.compiler.option.preprocessor.def.56223209" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" useByScannerDiscovery="false" valueType="definedSymbols"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1318830536" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1318830536" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.389117097" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base"> <tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.base.389117097" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.base">
@ -42,6 +43,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/QtAdvancedDockingSystem/src}&quot;"/> <listOptionValue builtIn="false" value="&quot;${workspace_loc:/QtAdvancedDockingSystem/src}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${QTDIR}/include&quot;"/> <listOptionValue builtIn="false" value="&quot;${QTDIR}/include&quot;"/>
</option> </option>
<option id="gnu.c.compiler.option.preprocessor.def.symbols.806805509" name="Defined symbols (-D)" superClass="gnu.c.compiler.option.preprocessor.def.symbols" useByScannerDiscovery="false" valueType="definedSymbols"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1568363924" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/> <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1568363924" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool> </tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.1734874312" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base"/> <tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.base.1734874312" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.base"/>

View File

@ -2,13 +2,13 @@
<project> <project>
<configuration id="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795" name="Default"> <configuration id="cdt.managedbuild.toolchain.gnu.mingw.base.1119687795" name="Default">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider"> <extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-853214798705706782" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD -std=c++14 &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
<provider class="org.eclipse.cdt.managedbuilder.internal.language.settings.providers.GCCBuiltinSpecsDetectorMinGW" console="false" env-hash="-797032510223863550" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetectorMinGW" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings MinGW" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="(g?cc)|([gc]\+\+)|(clang)" prefer-non-shared="true"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension> </extension>
</configuration> </configuration>

View File

@ -1,44 +1,47 @@
#include <QString> #include <QString>
#include <QFile> #include <QFile>
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include "mainwindow.h" #include <memory>
#include "mainwindow.h"
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit(); void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
switch (type) { {
case QtDebugMsg: QByteArray localMsg = msg.toLocal8Bit();
fprintf(stdout, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); switch (type) {
break; case QtDebugMsg:
case QtInfoMsg: fprintf(stdout, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stdout, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break;
break; case QtInfoMsg:
case QtWarningMsg: fprintf(stdout, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break;
break; case QtWarningMsg:
case QtCriticalMsg: fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break;
break; case QtCriticalMsg:
case QtFatalMsg: fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break;
abort(); case QtFatalMsg:
} fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
abort();
fflush(stderr); }
fflush(stdout);
} fflush(stderr);
fflush(stdout);
int main(int argc, char *argv[]) }
{
QApplication a(argc, argv); int main(int argc, char *argv[])
a.setQuitOnLastWindowClosed(true); {
qInstallMessageHandler(myMessageOutput); std::shared_ptr<int> b;
qDebug() << "Message handler test"; QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(true);
MainWindow mw; qInstallMessageHandler(myMessageOutput);
mw.show(); qDebug() << "Message handler test";
return a.exec();
} MainWindow mw;
mw.show();
return a.exec();
}

File diff suppressed because it is too large Load Diff

View File

@ -1,156 +1,166 @@
#ifndef DockOverlayH #ifndef DockOverlayH
#define DockOverlayH #define DockOverlayH
/******************************************************************************* /*******************************************************************************
** QtAdcancedDockingSystem ** QtAdcancedDockingSystem
** Copyright (C) 2017 Uwe Kindler ** Copyright (C) 2017 Uwe Kindler
** **
** This program is free software: you can redistribute it and/or modify ** 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 ** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or ** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version. ** (at your option) any later version.
** **
** This program is distributed in the hope that it will be useful, ** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of ** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details. ** GNU General Public License for more details.
** **
** You should have received a copy of the GNU General Public License ** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/ ******************************************************************************/
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include <QPointer> #include <QPointer>
#include <QHash> #include <QHash>
#include <QRect> #include <QRect>
#include <QFrame> #include <QFrame>
class QGridLayout; class QGridLayout;
#include "ads_globals.h" #include "ads_globals.h"
namespace ads namespace ads
{ {
struct DockOverlayPrivate; struct DockOverlayPrivate;
class CDockOverlayCross; class CDockOverlayCross;
/*! /*!
* DockOverlay paints a translucent rectangle over another widget. The geometry * DockOverlay paints a translucent rectangle over another widget. The geometry
* of the rectangle is based on the mouse location. * of the rectangle is based on the mouse location.
*/ */
class CDockOverlay : public QFrame class CDockOverlay : public QFrame
{ {
Q_OBJECT Q_OBJECT
private: private:
DockOverlayPrivate* d; //< private data class DockOverlayPrivate* d; //< private data class
friend class DockOverlayPrivate; friend class DockOverlayPrivate;
friend class DockOverlayCross; friend class DockOverlayCross;
public: public:
enum eMode enum eMode
{ {
ModeDockAreaOverlay, ModeDockAreaOverlay,
ModeContainerOverlay ModeContainerOverlay
}; };
/** /**
* Creates a dock overlay * Creates a dock overlay
*/ */
CDockOverlay(QWidget* parent, eMode Mode = ModeDockAreaOverlay); CDockOverlay(QWidget* parent, eMode Mode = ModeDockAreaOverlay);
/** /**
* Virtual destructor * Virtual destructor
*/ */
virtual ~CDockOverlay(); virtual ~CDockOverlay();
/** /**
* Configures the areas that are allowed for docking * Configures the areas that are allowed for docking
*/ */
void setAllowedAreas(DockWidgetAreas areas); void setAllowedAreas(DockWidgetAreas areas);
/** /**
* Returns flags with all allowed drop areas * Returns flags with all allowed drop areas
*/ */
DockWidgetAreas allowedAreas() const; DockWidgetAreas allowedAreas() const;
/** /**
* Returns the drop area under the current cursor location * Returns the drop area under the current cursor location
*/ */
DockWidgetArea dropAreaUnderCursor() const; DockWidgetArea dropAreaUnderCursor() const;
/** /**
* Show the drop overly for the given target widget * Show the drop overly for the given target widget
*/ */
DockWidgetArea showOverlay(QWidget* target); DockWidgetArea showOverlay(QWidget* target);
/** /**
* Hides the overlay * Hides the overlay
*/ */
void hideOverlay(); void hideOverlay();
/** /**
* Enables / disables the semi transparent overlay rectangle that represents * Enables / disables the semi transparent overlay rectangle that represents
* the future area of the dropped widget * the future area of the dropped widget
*/ */
void enableDropPreview(bool Enable); void enableDropPreview(bool Enable);
protected: /**
virtual void paintEvent(QPaintEvent *e) override; * The drop overlay rectangle for the target area
virtual void showEvent(QShowEvent* e) override; */
virtual void hideEvent(QHideEvent* e) override; QRect dropOverlayRect() const;
};
protected:
virtual void paintEvent(QPaintEvent *e) override;
struct DockOverlayCrossPrivate; virtual void showEvent(QShowEvent* e) override;
/*! virtual void hideEvent(QHideEvent* e) override;
* DockOverlayCross shows a cross with 5 different drop area possibilities. };
* I could have handled everything inside DockOverlay, but because of some
* styling issues it's better to have a separate class for the cross.
*/ struct DockOverlayCrossPrivate;
class CDockOverlayCross : public QWidget /*!
{ * DockOverlayCross shows a cross with 5 different drop area possibilities.
Q_OBJECT * I could have handled everything inside DockOverlay, but because of some
private: * styling issues it's better to have a separate class for the cross.
DockOverlayCrossPrivate* d; */
friend class DockOverlayCrossPrivate; class CDockOverlayCross : public QWidget
friend class CDockOverlay; {
Q_OBJECT
public: private:
/** DockOverlayCrossPrivate* d;
* Creates an overlay corss for the given overlay friend class DockOverlayCrossPrivate;
*/ friend class CDockOverlay;
CDockOverlayCross(CDockOverlay* overlay);
public:
/** /**
* Virtual destructor * Creates an overlay corss for the given overlay
*/ */
virtual ~CDockOverlayCross(); CDockOverlayCross(CDockOverlay* overlay);
/** /**
* Returns the dock widget area depending on the current cursor location. * Virtual destructor
* The function checks, if the mouse cursor is inside of any drop indicator */
* widget and returns the corresponding DockWidgetArea. virtual ~CDockOverlayCross();
*/
DockWidgetArea cursorLocation() const; /**
* Returns the dock widget area depending on the current cursor location.
/** * The function checks, if the mouse cursor is inside of any drop indicator
* Sets up the overlay cross for the given overlay mode * widget and returns the corresponding DockWidgetArea.
*/ */
void setupOverlayCross(CDockOverlay::eMode Mode); DockWidgetArea cursorLocation() const;
/** /**
* Resets and updates the * Sets up the overlay cross for the given overlay mode
*/ */
void reset(); void setupOverlayCross(CDockOverlay::eMode Mode);
protected: /**
virtual void showEvent(QShowEvent* e) override; * Resets and updates the
void setAreaWidgets(const QHash<DockWidgetArea, QWidget*>& widgets); */
void reset();
private:
/**
}; // CDockOverlayCross * Updates the current position
*/
} // namespace ads void updatePosition();
#endif // DockOverlayH
protected:
virtual void showEvent(QShowEvent* e) override;
void setAreaWidgets(const QHash<DockWidgetArea, QWidget*>& widgets);
private:
}; // CDockOverlayCross
} // namespace ads
#endif // DockOverlayH

View File

@ -1,43 +1,74 @@
//============================================================================ //============================================================================
/// \file DockSplitter.cpp /// \file DockSplitter.cpp
/// \author Uwe Kindler /// \author Uwe Kindler
/// \date 24.03.2017 /// \date 24.03.2017
/// \brief Implementation of CDockSplitter /// \brief Implementation of CDockSplitter
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include <DockSplitter.h> #include "DockSplitter.h"
#include <QDebug> #include <QDebug>
#include <QChildEvent>
namespace ads
{ #include "DockAreaWidget.h"
//============================================================================ namespace ads
CDockSplitter::~CDockSplitter() {
{ /**
qDebug() << "~CDockSplitter"; * Private dock splitter data
} */
struct DockSplitterPrivate
{
//============================================================================ CDockSplitter* _this;
bool CDockSplitter::hasVisibleContent() const int VisibleContentCount = 0;
{
// TODO Cache or precalculate this to speed up DockSplitterPrivate(CDockSplitter* _public) : _this(_public) {}
for (int i = 0; i < count(); ++i) };
{
if (widget(i)->isVisibleTo(this)) //============================================================================
{ CDockSplitter::CDockSplitter(QWidget *parent)
return true; : QSplitter(parent),
} d(new DockSplitterPrivate(this))
} {
return false; }
}
} // namespace ads //============================================================================
CDockSplitter::CDockSplitter(Qt::Orientation orientation, QWidget *parent)
//--------------------------------------------------------------------------- : QSplitter(orientation, parent),
// EOF DockSplitter.cpp d(new DockSplitterPrivate(this))
{
}
//============================================================================
CDockSplitter::~CDockSplitter()
{
qDebug() << "~CDockSplitter";
delete d;
}
//============================================================================
bool CDockSplitter::hasVisibleContent() const
{
// TODO Cache or precalculate this to speed up
for (int i = 0; i < count(); ++i)
{
if (widget(i)->isVisibleTo(this))
{
return true;
}
}
return false;
}
} // namespace ads
//---------------------------------------------------------------------------
// EOF DockSplitter.cpp

View File

@ -1,41 +1,47 @@
#ifndef DockSplitterH #ifndef DockSplitterH
#define DockSplitterH #define DockSplitterH
//============================================================================ //============================================================================
/// \file DockSplitter.h /// \file DockSplitter.h
/// \author Uwe Kindler /// \author Uwe Kindler
/// \date 24.03.2017 /// \date 24.03.2017
/// \brief Declaration of CDockSplitter /// \brief Declaration of CDockSplitter
//============================================================================ //============================================================================
//============================================================================ //============================================================================
// INCLUDES // INCLUDES
//============================================================================ //============================================================================
#include <QSplitter> #include <QSplitter>
namespace ads namespace ads
{ {
struct DockSplitterPrivate;
/**
* Splitter used internally instead of QSplitter /**
*/ * Splitter used internally instead of QSplitter
class CDockSplitter : public QSplitter */
{ class CDockSplitter : public QSplitter
Q_OBJECT {
public: Q_OBJECT
using QSplitter::QSplitter; private:
DockSplitterPrivate* d;
/** friend class DockSplitterPrivate;
* Prints debug info
*/ public:
virtual ~CDockSplitter(); CDockSplitter(QWidget *parent = Q_NULLPTR);
CDockSplitter(Qt::Orientation orientation, QWidget *parent = Q_NULLPTR);
/**
* Returns true, if any of the internal widgets is visible /**
*/ * Prints debug info
bool hasVisibleContent() const; */
}; // class CDockSplitter virtual ~CDockSplitter();
} // namespace ads /**
* Returns true, if any of the internal widgets is visible
//--------------------------------------------------------------------------- */
#endif // DockSplitterH bool hasVisibleContent() const;
}; // class CDockSplitter
} // namespace ads
//---------------------------------------------------------------------------
#endif // DockSplitterH

View File

@ -43,6 +43,7 @@
#include "DockWidget.h" #include "DockWidget.h"
#include "DockOverlay.h" #include "DockOverlay.h"
#include <iostream>
namespace ads namespace ads
{ {
@ -91,6 +92,18 @@ void FloatingDockContainerPrivate::titleMouseReleaseEvent()
return; return;
} }
// Resize the floating widget to the size of the highlighted drop area
// rectangle
QRect Rect = DockManager->containerOverlay()->dropOverlayRect();
if (!Rect.isValid())
{
Rect = DockManager->dockAreaOverlay()->rect();
}
if (Rect.isValid())
{
_this->resize(Rect.size());
}
DropContainer->dropFloatingWidget(_this, QCursor::pos()); DropContainer->dropFloatingWidget(_this, QCursor::pos());
DockManager->containerOverlay()->hideOverlay(); DockManager->containerOverlay()->hideOverlay();
DockManager->dockAreaOverlay()->hideOverlay(); DockManager->dockAreaOverlay()->hideOverlay();