mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-02-24 17:31:36 +08:00
Added ElidingLabel to support text eliding for dock area tabs, removed debug output
This commit is contained in:
parent
74b9d35c7b
commit
a4838a41ac
@ -1,3 +1,22 @@
|
||||
/*******************************************************************************
|
||||
** Qt Advanced Docking System
|
||||
** Copyright (C) 2017 Uwe Kindler
|
||||
**
|
||||
** This 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, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file DockAreaTabBar.cpp
|
||||
/// \author Uwe Kindler
|
||||
@ -24,7 +43,6 @@
|
||||
#include "DockWidget.h"
|
||||
#include "DockWidgetTab.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -186,8 +204,6 @@ void CDockAreaTabBar::mouseMoveEvent(QMouseEvent* ev)
|
||||
return;
|
||||
}
|
||||
|
||||
/*int DragDistanceY = qAbs(d->DragStartMousePos.y() - ev->pos().y());
|
||||
int MinDragDistanceY = this->height() / 2;*/
|
||||
int DragDistance = (d->DragStartMousePos - ev->pos()).manhattanLength();
|
||||
if (DragDistance >= CDockManager::startDragDistance())
|
||||
{
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*******************************************************************************
|
||||
** Qt Advanced Docking System
|
||||
** Copyright (C) 2017 Uwe Kindler
|
||||
**
|
||||
** This 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, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file DockAreaTitleBar.cpp
|
||||
/// \author Uwe Kindler
|
||||
@ -29,7 +48,6 @@
|
||||
#include "DockWidgetTab.h"
|
||||
#include "DockAreaTabBar.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -226,7 +244,6 @@ void CDockAreaTitleBar::onCloseButtonClicked()
|
||||
//============================================================================
|
||||
void CDockAreaTitleBar::onUndockButtonClicked()
|
||||
{
|
||||
std::cout << "CDockAreaTitleBar::onUndockButtonClicked" << std::endl;
|
||||
d->TabBar->makeAreaFloating(mapFromGlobal(QCursor::pos()));
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,6 @@
|
||||
#include "DockSplitter.h"
|
||||
#include "DockAreaTitleBar.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -392,7 +390,6 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
|
||||
void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
||||
{
|
||||
qDebug() << "CDockAreaWidget::removeDockWidget";
|
||||
std::cout << "CDockAreaWidget::removeDockWidget" << std::endl;
|
||||
auto NextOpenDockWidget = nextOpenDockWidget(DockWidget);
|
||||
|
||||
d->ContentsLayout->removeWidget(DockWidget);
|
||||
@ -434,7 +431,6 @@ void CDockAreaWidget::removeDockWidget(CDockWidget* DockWidget)
|
||||
//============================================================================
|
||||
void CDockAreaWidget::hideAreaWithNoVisibleContent()
|
||||
{
|
||||
std::cout << "CDockAreaWidget::hideAreaWithNoVisibleContent()" << std::endl;
|
||||
this->toggleView(false);
|
||||
|
||||
// Hide empty parent splitter
|
||||
|
@ -49,7 +49,6 @@
|
||||
#include "DockSplitter.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace ads
|
||||
|
@ -28,6 +28,7 @@
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <ElidingLabel.h>
|
||||
#include "DockWidgetTab.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
@ -45,8 +46,6 @@
|
||||
#include "DockOverlay.h"
|
||||
#include "DockManager.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
@ -60,6 +59,7 @@ enum eDragState
|
||||
DraggingFloatingWidget//!< DraggingFloatingWidget
|
||||
};
|
||||
|
||||
using tTabLabel = CElidingLabel;
|
||||
|
||||
/**
|
||||
* Private data class of CDockWidgetTab class (pimpl)
|
||||
@ -69,7 +69,7 @@ struct DockWidgetTabPrivate
|
||||
CDockWidgetTab* _this;
|
||||
CDockWidget* DockWidget;
|
||||
QLabel* IconLabel;
|
||||
QLabel* TitleLabel;
|
||||
tTabLabel* TitleLabel;
|
||||
QPoint DragStartMousePosition;
|
||||
bool IsActiveTab = false;
|
||||
CDockAreaWidget* DockArea = nullptr;
|
||||
@ -137,15 +137,17 @@ void DockWidgetTabPrivate::createLayout()
|
||||
|
||||
IconLabel = new QLabel();
|
||||
IconLabel->setAlignment(Qt::AlignVCenter);
|
||||
IconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
l->addWidget(IconLabel, Qt::AlignVCenter);
|
||||
|
||||
TitleLabel = new QLabel();
|
||||
TitleLabel = new tTabLabel();
|
||||
TitleLabel->setElideMode(Qt::ElideRight);
|
||||
TitleLabel->setText(DockWidget->windowTitle());
|
||||
TitleLabel->setObjectName("dockWidgetTabLabel");
|
||||
l->addWidget(TitleLabel, 1);
|
||||
|
||||
IconLabel->setVisible(false);
|
||||
TitleLabel->setVisible(true);
|
||||
TitleLabel->setText(DockWidget->windowTitle());
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
|
198
src/ElidingLabel.cpp
Normal file
198
src/ElidingLabel.cpp
Normal file
@ -0,0 +1,198 @@
|
||||
/*******************************************************************************
|
||||
** Qt Advanced Docking System
|
||||
** Copyright (C) 2017 Uwe Kindler
|
||||
**
|
||||
** This 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, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file ElidingLabel.cpp
|
||||
/// \author Uwe Kindler
|
||||
/// \date 05.11.2018
|
||||
/// \brief Implementation of CElidingLabel
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <ElidingLabel.h>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
namespace ads
|
||||
{
|
||||
/**
|
||||
* Private data of public CClickableLabel
|
||||
*/
|
||||
struct ElidingLabelPrivate
|
||||
{
|
||||
CElidingLabel* _this;
|
||||
Qt::TextElideMode ElideMode = Qt::ElideNone;
|
||||
QString Text;
|
||||
|
||||
ElidingLabelPrivate(CElidingLabel* _public) : _this(_public) {}
|
||||
|
||||
void elideText(int Width);
|
||||
|
||||
/**
|
||||
* Convenience function to check if the
|
||||
*/
|
||||
bool isModeElideNone() const
|
||||
{
|
||||
return Qt::ElideNone == ElideMode;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
void ElidingLabelPrivate::elideText(int Width)
|
||||
{
|
||||
if (isModeElideNone())
|
||||
{
|
||||
return;
|
||||
}
|
||||
QFontMetrics fm = _this->fontMetrics();
|
||||
QString str = fm.elidedText(Text, ElideMode, Width - _this->margin() * 2 - _this->indent());
|
||||
if (str == "…")
|
||||
{
|
||||
str = Text.at(0);
|
||||
}
|
||||
_this->QLabel::setText(str);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CElidingLabel::CElidingLabel(QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(parent, f),
|
||||
d(new ElidingLabelPrivate(this))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CElidingLabel::CElidingLabel(const QString& text, QWidget* parent, Qt::WindowFlags f)
|
||||
: QLabel(text, parent,f),
|
||||
d(new ElidingLabelPrivate(this))
|
||||
{
|
||||
d->Text = text;
|
||||
setToolTip(text);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
CElidingLabel::~CElidingLabel()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
Qt::TextElideMode CElidingLabel::elideMode() const
|
||||
{
|
||||
return d->ElideMode;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::setElideMode(Qt::TextElideMode mode)
|
||||
{
|
||||
d->ElideMode = mode;
|
||||
d->elideText(size().width());
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() != Qt::LeftButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
emit clicked();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::mouseDoubleClickEvent( QMouseEvent *ev )
|
||||
{
|
||||
Q_UNUSED(ev)
|
||||
emit doubleClicked();
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
if (!d->isModeElideNone())
|
||||
{
|
||||
d->elideText(event->size().width());
|
||||
}
|
||||
QLabel::resizeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CElidingLabel::minimumSizeHint() const
|
||||
{
|
||||
if (pixmap() != nullptr || d->isModeElideNone())
|
||||
{
|
||||
return QLabel::minimumSizeHint();
|
||||
}
|
||||
const QFontMetrics &fm = fontMetrics();
|
||||
QSize size(fm.width("…"), fm.height());
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QSize CElidingLabel::sizeHint() const
|
||||
{
|
||||
if (pixmap() != nullptr || d->isModeElideNone())
|
||||
{
|
||||
return QLabel::sizeHint();
|
||||
}
|
||||
const QFontMetrics& fm = fontMetrics();
|
||||
QSize size(fm.width(d->Text), QLabel::sizeHint().height());
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void CElidingLabel::setText(const QString &text)
|
||||
{
|
||||
if (d->isModeElideNone())
|
||||
{
|
||||
Super::setText(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
d->Text = text;
|
||||
setToolTip( text );
|
||||
d->elideText(this->size().width());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
QString CElidingLabel::text() const
|
||||
{
|
||||
return d->Text;
|
||||
}
|
||||
} // namespace QtLabb
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// EOF ClickableLabel.cpp
|
97
src/ElidingLabel.h
Normal file
97
src/ElidingLabel.h
Normal file
@ -0,0 +1,97 @@
|
||||
#ifndef ElidingLabelH
|
||||
#define ElidingLabelH
|
||||
/*******************************************************************************
|
||||
** Qt Advanced Docking System
|
||||
** Copyright (C) 2017 Uwe Kindler
|
||||
**
|
||||
** This 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, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \file ElidingLabel.h
|
||||
/// \author Uwe Kindler
|
||||
/// \date 05.11.2018
|
||||
/// \brief Declaration of CElidingLabel
|
||||
//============================================================================
|
||||
|
||||
//============================================================================
|
||||
// INCLUDES
|
||||
//============================================================================
|
||||
#include <QLabel>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
struct ElidingLabelPrivate;
|
||||
|
||||
/**
|
||||
* A QLabel that supports eliding text.
|
||||
* Because the functions setText() and text() are no virtual functions setting
|
||||
* and reading the text via a pointer to the base class QLabel does not work
|
||||
* properly
|
||||
*/
|
||||
class CElidingLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
ElidingLabelPrivate* d;
|
||||
friend class ElidingLabelPrivate;
|
||||
|
||||
protected:
|
||||
virtual void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
virtual void resizeEvent( QResizeEvent *event ) override;
|
||||
virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override;
|
||||
|
||||
public:
|
||||
using Super = QLabel;
|
||||
|
||||
CElidingLabel(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
CElidingLabel(const QString& text, QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
virtual ~CElidingLabel();
|
||||
|
||||
/**
|
||||
* Returns the text elide mode.
|
||||
* The default mode is ElideNone
|
||||
*/
|
||||
Qt::TextElideMode elideMode() const;
|
||||
|
||||
/**
|
||||
* Sets the text elide mode
|
||||
*/
|
||||
void setElideMode(Qt::TextElideMode mode);
|
||||
|
||||
|
||||
public: // reimplements QLabel ----------------------------------------------
|
||||
virtual QSize minimumSizeHint() const override;
|
||||
virtual QSize sizeHint() const override;
|
||||
void setText(const QString &text);
|
||||
QString text() const;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* This signal is emitted if the user clicks on the label (i.e. pressed
|
||||
* down then released while the mouse cursor is inside the label)
|
||||
*/
|
||||
void clicked();
|
||||
|
||||
/**
|
||||
* This signal is emitted if the user does a double click on the label
|
||||
*/
|
||||
void doubleClicked();
|
||||
}; //class CElidingLabel
|
||||
|
||||
} // namespace QtLabb
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
#endif // ElidingLabelH
|
@ -44,7 +44,6 @@
|
||||
#include "DockWidget.h"
|
||||
#include "DockOverlay.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace ads
|
||||
{
|
||||
@ -334,8 +333,7 @@ void CFloatingDockContainer::closeEvent(QCloseEvent *event)
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::hideEvent(QHideEvent *event)
|
||||
{
|
||||
std::cout << "CFloatingDockContainer hideEvent" << std::endl;
|
||||
QWidget::hideEvent(event);
|
||||
Super::hideEvent(event);
|
||||
for (auto DockArea : d->DockContainer->openedDockAreas())
|
||||
{
|
||||
for (auto DockWidget : DockArea->openedDockWidgets())
|
||||
@ -349,8 +347,7 @@ void CFloatingDockContainer::hideEvent(QHideEvent *event)
|
||||
//============================================================================
|
||||
void CFloatingDockContainer::showEvent(QShowEvent *event)
|
||||
{
|
||||
std::cout << "CFloatingDockContainer showEvent" << std::endl;
|
||||
QWidget::showEvent(event);
|
||||
Super::showEvent(event);
|
||||
/*for (auto DockArea : d->DockContainer->openedDockAreas())
|
||||
{
|
||||
for (auto DockWidget : DockArea->openedDockWidgets())
|
||||
@ -507,8 +504,6 @@ void CFloatingDockContainer::updateWindowTitle()
|
||||
void CFloatingDockContainer::onDockAreaCurrentChanged(int Index)
|
||||
{
|
||||
Q_UNUSED(Index);
|
||||
std::cout << "CFloatingDockContainer::onDockAreaCurrentChanged "
|
||||
<< Index << std::endl;
|
||||
this->setWindowTitle(d->SingleDockArea->currentDockWidget()->windowTitle());
|
||||
}
|
||||
|
||||
@ -521,7 +516,6 @@ bool CFloatingDockContainer::restoreState(QXmlStreamReader& Stream, bool Testing
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Dockarea count " << d->DockContainer->dockAreaCount() << std::endl;
|
||||
onDockAreasAddedOrRemoved();
|
||||
return true;
|
||||
}
|
||||
|
@ -113,6 +113,8 @@ protected: // reimplements QWidget
|
||||
virtual bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
public:
|
||||
using Super = QWidget;
|
||||
|
||||
/**
|
||||
* Create empty flatingb widget - required for restore state
|
||||
*/
|
||||
|
@ -41,7 +41,8 @@ HEADERS += \
|
||||
FloatingDockContainer.h \
|
||||
DockOverlay.h \
|
||||
DockSplitter.h \
|
||||
DockAreaTitleBar.h
|
||||
DockAreaTitleBar.h \
|
||||
ElidingLabel.h
|
||||
|
||||
|
||||
|
||||
@ -56,4 +57,5 @@ SOURCES += \
|
||||
FloatingDockContainer.cpp \
|
||||
DockOverlay.cpp \
|
||||
DockSplitter.cpp \
|
||||
DockAreaTitleBar.cpp
|
||||
DockAreaTitleBar.cpp \
|
||||
ElidingLabel.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user