Fixed several issues detected during testing / review (refs #304)

* MS report 1-5 https://dev.vatsim-germany.org/issues/304#change-1800
* Clang warning https://dev.vatsim-germany.org/boards/22/topics/1982?r=1997#message-1997
* Wrong indexes for dockable widgets, RW: https://dev.vatsim-germany.org/issues/304#note-13
* Fixed wrong offset in Fsuipc class
* Improved position handling for floating widgets opened 1st time
This commit is contained in:
Klaus Basan
2014-08-05 18:31:22 +02:00
parent 3c12cd7b30
commit 600ea2b803
15 changed files with 127 additions and 127 deletions

View File

@@ -310,8 +310,7 @@ namespace BlackCore
// warnings, if required
if (!illegalIcaoCodes.isEmpty())
{
const QString w = QString("Illegal ICAO code(s) in VATSIM data file: %1").arg(illegalIcaoCodes.join(", "));
qWarning(w.toLatin1());
qWarning() << "Illegal ICAO code(s) in VATSIM data file:" << illegalIcaoCodes.join(", ");
}
}
}

View File

@@ -43,7 +43,6 @@ namespace BlackGui
this->connectAllWidgets();
this->setFeaturesForDockableWidgets(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable);
this->tabifyAllWidgets();
this->setPreferredSizesWhenFloating();
// context menu
this->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -103,7 +102,7 @@ namespace BlackGui
subMenuDisplay->addAction(displayMenuAction);
c = connect(displayMenuAction, SIGNAL(triggered(bool)), signalMapperDisplay, SLOT(map()));
Q_ASSERT(c);
signalMapperDisplay->setMapping(displayMenuAction, i);
signalMapperDisplay->setMapping(displayMenuAction, i); // action to index
}
c = connect(signalMapperToggleFloating, SIGNAL(mapped(int)), this, SLOT(toggleFloating(int)));
Q_ASSERT(c);
@@ -187,10 +186,8 @@ namespace BlackGui
void CMainInfoAreaComponent::adjustSizeForAllDockWidgets()
{
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
CDockWidgetInfoArea *dw = (*i);
dw->adjustSize();
}
}
@@ -199,11 +196,18 @@ namespace BlackGui
{
// I fake the double click here, which queues the events in the queue
// and hence fires all depending signals in order
if (!this->m_tabBar) return;
for (int i = 0; i < this->m_tabBar->count(); i++)
// if (!this->m_tabBar) return;
// for (int i = 0; i < this->m_tabBar->count(); i++)
// {
// // emit this->m_tabBar->tabBarDoubleClicked(i);
// this->toggleFloating(i);
// }
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
emit this->m_tabBar->tabBarDoubleClicked(i);
if (dw->isFloating()) continue;
dw->toggleFloating();
}
}
void CMainInfoAreaComponent::toggleFloating()
@@ -259,10 +263,8 @@ namespace BlackGui
void CMainInfoAreaComponent::ps_setDockArea(Qt::DockWidgetArea area)
{
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
CDockWidgetInfoArea *dw = (*i);
Qt::DockWidgetAreas newAreas = static_cast<Qt::DockWidgetAreas>(area);
Qt::DockWidgetAreas oldAreas = dw->allowedAreas();
if (oldAreas == newAreas) continue;
@@ -273,6 +275,7 @@ namespace BlackGui
void CMainInfoAreaComponent::ps_setInfoAreaFloating(bool floating)
{
// float whole info area
this->m_infoAreaFloating = floating;
if (this->m_infoAreaFloating)
{
@@ -297,9 +300,7 @@ namespace BlackGui
{
// this->setDockArea(Qt::LeftDockWidgetArea);
this->setTabPosition(Qt::LeftDockWidgetArea, QTabWidget::East);
bool init = this->m_tabBar ? false : true;
QPoint pos = CGuiUtility::assumedMainWindowPosition(); //main window pos. not initialized yet
if (!this->m_dockableWidgets.isEmpty())
{
@@ -310,15 +311,17 @@ namespace BlackGui
Q_ASSERT(after);
// trick, init widget as floating
// this completely initializes the tab bar and all docked widgets
if (init)
{
QPoint initPoint(pos.rx() + i * 25, pos.ry() + i * 20);
QPoint offset(i * 25, i * 20);
after->setVisible(false);
after->setFloating(true);
after->move(initPoint);
after->setOffsetWhenFloating(offset);
after->setPreferredSizeWhenFloating(CMainInfoAreaComponent::getPreferredSizeWhenFloating(static_cast<InfoArea>(i)));
after->setFloating(false);
after->resetWasAlreadyFLoating();
after->setVisible(true);
after->resetWasAlreadyFLoating();
}
else
{
@@ -339,7 +342,8 @@ namespace BlackGui
this->m_tabBar->setObjectName("comp_MainInfoAreaDockWidgetTab");
this->m_tabBar->setMovable(false);
this->m_tabBar->setElideMode(Qt::ElideNone);
this->setDocumentMode(true);
this->setDocumentMode(true); // did not notice any effect
this->setTabPixmaps();
// East / West does not work (shown, but area itself empty)
// South does not have any effect
@@ -347,7 +351,6 @@ namespace BlackGui
connect(this->m_tabBar, &QTabBar::tabBarDoubleClicked, this, &CMainInfoAreaComponent::ps_tabBarDoubleClicked);
}
this->setTabPixmaps();
if (this->countDockedWidgets() > 0)
{
this->m_tabBar->setCurrentIndex(0);
@@ -368,57 +371,50 @@ namespace BlackGui
void CMainInfoAreaComponent::connectAllWidgets()
{
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
connect(*i, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CMainInfoAreaComponent::ps_onWidgetTopLevelChanged);
connect(dw, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CMainInfoAreaComponent::ps_onWidgetTopLevelChanged);
}
}
void CMainInfoAreaComponent::setMarginsWhenFloating(int left, int top, int right, int bottom)
{
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
//! Margins when window is floating
(*i)->setMarginsWhenFloating(left, top, right, bottom);
dw->setMarginsWhenFloating(left, top, right, bottom);
}
}
void CMainInfoAreaComponent::setMarginsWhenDocked(int left, int top, int right, int bottom)
{
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
//! Margins when window is floating
(*i)->setMarginsWhenDocked(left, top, right, bottom);
//! Margins when window is docked
dw->setMarginsWhenDocked(left, top, right, bottom);
}
}
void CMainInfoAreaComponent::setPreferredSizesWhenFloating()
QSize CMainInfoAreaComponent::getPreferredSizeWhenFloating(InfoArea area)
{
if (this->m_dockableWidgets.isEmpty()) return;
for (int i = 0; i < this->m_dockableWidgets.size(); i++)
switch (area)
{
InfoArea ia = static_cast<InfoArea>(i);
switch (ia)
{
case InfoAreaAircrafts:
case InfoAreaAtc:
case InfoAreaUsers:
case InfoAreaLog:
case InfoAreaSimulator:
this->m_dockableWidgets[i]->setPreferredSizeWhenFloating(QSize(400, 300));
break;
case InfoAreaMappings:
case InfoAreaSettings:
case InfoAreaTextMessages:
case InfoAreaFlightPlan:
this->m_dockableWidgets[i]->setPreferredSizeWhenFloating(QSize(600, 400));
break;
default:
break;
}
case InfoAreaAircrafts:
case InfoAreaAtc:
case InfoAreaUsers:
case InfoAreaLog:
case InfoAreaSimulator:
return QSize(400, 300);
break;
case InfoAreaMappings:
case InfoAreaSettings:
case InfoAreaTextMessages:
case InfoAreaFlightPlan:
return QSize(600, 400);
break;
default:
return QSize(400, 300);
break;
}
}
@@ -451,34 +447,31 @@ namespace BlackGui
}
}
CDockWidgetInfoArea *CMainInfoAreaComponent::getDockableWidgetByIndex(int index) const
{
if (index >= this->m_dockableWidgets.count() || index < 0) return nullptr;
return this->m_dockableWidgets.at(index);
}
CDockWidgetInfoArea *CMainInfoAreaComponent::selectedDockableWidget() const
{
if (!this->m_tabBar) return nullptr;
int i = this->m_tabBar->currentIndex();
return getDockableWidgetByIndex(i);
}
int CMainInfoAreaComponent::countDockedWidgets() const
{
if (!this->m_tabBar) return 0;
return this->m_tabBar->count();
}
CDockWidgetInfoArea *CMainInfoAreaComponent::getDockableWidgetByTabIndex(int tabBarIndex) const
{
if (tabBarIndex >= this->m_dockableWidgets.count() || tabBarIndex < 0) return nullptr;
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
if (dw->isFloating()) continue; // not in tab bar
if (tabBarIndex == 0) return dw;
tabBarIndex--;
}
return nullptr;
}
int CMainInfoAreaComponent::widgetToTabBarIndex(const CDockWidgetInfoArea *dockWidget)
{
if (!dockWidget) return -1;
if (dockWidget->isFloating()) return -1;
int tabBarIndex = 0;
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
CDockWidgetInfoArea *dw = (*i);
if (dw->isFloating()) continue; // not in tab bar
if (dw == dockWidget) return tabBarIndex;
tabBarIndex++;
@@ -488,9 +481,8 @@ namespace BlackGui
void CMainInfoAreaComponent::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features)
{
for (int i = 0; i < this->m_dockableWidgets.size(); i++)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
CDockWidgetInfoArea *dw = this->m_dockableWidgets.at(i);
dw->setFeatures(features);
}
}
@@ -506,11 +498,9 @@ namespace BlackGui
}
}
void CMainInfoAreaComponent::ps_tabBarDoubleClicked(int index)
void CMainInfoAreaComponent::ps_tabBarDoubleClicked(int tabBarIndex)
{
CDockWidgetInfoArea *dw = (index >= 0) ?
this->getDockableWidgetByIndex(index) :
this->selectedDockableWidget();
CDockWidgetInfoArea *dw = this->getDockableWidgetByTabIndex(tabBarIndex);
if (!dw) return;
dw->toggleFloating();
}
@@ -529,7 +519,6 @@ namespace BlackGui
{
QString qss = CStyleSheetUtility::instance().style(CStyleSheetUtility::fileNameMainInfoArea());
this->setStyleSheet(qss);
if (this->m_tabBar)
{
QString qss = CStyleSheetUtility::instance().style(CStyleSheetUtility::fileNameDockWidgetTab());
@@ -551,10 +540,8 @@ namespace BlackGui
{
if (show == this->m_showTabTexts) return;
this->m_showTabTexts = show;
QList<CDockWidgetInfoArea *>::iterator i;
for (i = this->m_dockableWidgets.begin(); i != this->m_dockableWidgets.end(); ++i)
for (CDockWidgetInfoArea *dw : this->m_dockableWidgets)
{
CDockWidgetInfoArea *dw = (*i);
dw->showTitleWhenDocked(show);
}
}

View File

@@ -139,11 +139,8 @@ namespace BlackGui
//! Corresponding dockable widgets
QList<CDockWidgetInfoArea *> dockableWidgets() const;
//! Corresponding dockable widget
CDockWidgetInfoArea *getDockableWidgetByIndex(int index) const;
//! Selected dockable widget
CDockWidgetInfoArea *selectedDockableWidget() const;
//! Corresponding dockable widget for given tab index
CDockWidgetInfoArea *getDockableWidgetByTabIndex(int tabBarIndex) const;
//! Features of the dockable widgets
void setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features);
@@ -167,14 +164,14 @@ namespace BlackGui
void setMarginsWhenDocked(int left, int top, int right, int bottom);
//! Set window sizes when floating
void setPreferredSizesWhenFloating();
static QSize getPreferredSizeWhenFloating(InfoArea area);
//! Info area to icon
static const QPixmap &infoAreaToPixmap(InfoArea infoArea);
private slots:
//! Tab bar has been double clicked
void ps_tabBarDoubleClicked(int index);
void ps_tabBarDoubleClicked(int tabBarIndex);
//! A widget has changed its top level
void ps_onWidgetTopLevelChanged(CDockWidget *widget, bool topLevel);

View File

@@ -33,7 +33,7 @@ namespace BlackGui
this->ui->tvp_LiveData->addOrUpdateByName(name, value, icon);
}
void CSimulatorComponent::addOrUpdateByName(const QString &name, const QString &value, CIcons::IconIndexes iconIndex)
void CSimulatorComponent::addOrUpdateByName(const QString &name, const QString &value, CIcons::IconIndex iconIndex)
{
this->addOrUpdateByName(name, value, CIconList::iconForIndex(iconIndex));
}

View File

@@ -39,7 +39,7 @@ namespace BlackGui
void addOrUpdateByName(const QString &name, const QString &value, const BlackMisc::CIcon &icon);
//! Simple add or update name / value pair
void addOrUpdateByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndexes iconIndex);
void addOrUpdateByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex);
//! Number of entries
int rowCount() const;

View File

@@ -10,6 +10,7 @@
#include "dockwidget.h"
#include "blackmisc/icons.h"
#include "blackgui/stylesheetutility.h"
#include "blackgui/guiutility.h"
#include <QCloseEvent>
#include <QStyleOption>
#include <QPainter>
@@ -126,6 +127,15 @@ namespace BlackGui
{
this->resize(this->m_preferredSizeWhenFloating);
}
// and move
QPoint mainWindowPos = BlackGui::CGuiUtility::mainWindowPosition();
if (!mainWindowPos.isNull())
{
int x = mainWindowPos.x() + this->m_offsetWhenFloating.x();
int y = mainWindowPos.y() + this->m_offsetWhenFloating.y();
this->move(x, y);
}
}
this->m_wasAlreadyFloating = true;
}

View File

@@ -66,9 +66,12 @@ namespace BlackGui
//! Was widget already floating
bool wasAlreadyFloating() const { return this->m_wasAlreadyFloating; }
//! Size when floating
//! Size when floating first time
void setPreferredSizeWhenFloating(const QSize &size) { this->m_preferredSizeWhenFloating = size; }
//! Position offset when floating first time
void setOffsetWhenFloating(const QPoint &point) { this->m_offsetWhenFloating = point; }
public slots:
//! Toggle floating
void toggleFloating();
@@ -109,7 +112,8 @@ namespace BlackGui
QString m_windowTitleBackup; //!< original title, even if the widget title is deleted for layout purposes
bool m_windowTitleWhenDocked = true;
bool m_wasAlreadyFloating = false;
QSize m_preferredSizeWhenFloating;
QSize m_preferredSizeWhenFloating; //!< preferred size men floating 1st time
QPoint m_offsetWhenFloating; //!< initial offset to main window when floating first time
//! Empty widget with no size
void initTitleBarWidgets();

View File

@@ -21,38 +21,48 @@ namespace BlackGui
this->read();
}
const QString CStyleSheetUtility::fontStyleAsString(const QFont &font)
const QString &CStyleSheetUtility::fontStyleAsString(const QFont &font)
{
static const QString n("normal");
static const QString i("italic");
static const QString o("oblique");
static const QString e;
switch (font.style())
{
case QFont::StyleNormal: return "normal";
case QFont::StyleItalic: return "italic";
case QFont::StyleOblique: return "oblique";
default: return "";
case QFont::StyleNormal: return n;
case QFont::StyleItalic: return i;
case QFont::StyleOblique: return o;
default: return e;
}
}
const QString CStyleSheetUtility::fontWeightAsString(const QFont &font)
const QString &CStyleSheetUtility::fontWeightAsString(const QFont &font)
{
if (font.weight() < static_cast<int>(QFont::Normal))
{
return "light";
static const QString l("light");
return l;
}
else if (font.weight() < static_cast<int>(QFont::DemiBold))
{
return "normal";
static const QString n("normal");
return n;
}
else if (font.weight() < static_cast<int>(QFont::Bold))
{
return "demibold";
static const QString d("demibold");
return d;
}
else if (font.weight() < static_cast<int>(QFont::Black))
{
return "bold";
static const QString b("bold");
return b;
}
else
{
return "black";
static const QString b("black");
return b;
}
}

View File

@@ -96,10 +96,10 @@ namespace BlackGui
explicit CStyleSheetUtility(QObject *parent = nullptr);
//! Font style as string
static const QString fontStyleAsString(const QFont &font);
static const QString &fontStyleAsString(const QFont &font);
//! Font weight as string
static const QString fontWeightAsString(const QFont &font);
static const QString &fontWeightAsString(const QFont &font);
};
}

View File

@@ -28,7 +28,7 @@ namespace BlackMisc
CIcon() {}
//! Constructor.
CIcon(CIcons::IconIndexes index, const QString &descriptiveText) :
CIcon( CIcons::IconIndex index, const QString &descriptiveText) :
m_index(static_cast<int>(index)), m_descriptiveText(descriptiveText) {}
//! \copydoc CValueObject::toQVariant
@@ -38,7 +38,7 @@ namespace BlackMisc
const QString &getDescriptiveText() const { return this->m_descriptiveText; }
//! Index
CIcons::IconIndexes getIndex() const { return static_cast<CIcons::IconIndexes>(this->m_index);}
CIcons::IconIndex getIndex() const { return static_cast< CIcons::IconIndex>(this->m_index);}
//! Corresponding pixmap
QPixmap toPixmap() const;

View File

@@ -15,7 +15,7 @@ namespace BlackMisc
CSequence<CIcon>(other)
{ }
CIcon CIconList::findByIndex(CIcons::IconIndexes index) const
CIcon CIconList::findByIndex(CIcons::IconIndex index) const
{
return this->findBy(&CIcon::getIndex, index).frontOrDefault();
}

View File

@@ -34,7 +34,7 @@ namespace BlackMisc
CIconList(const CSequence<CIcon> &other);
//! Find by index
CIcon findByIndex(CIcons::IconIndexes index) const;
CIcon findByIndex(CIcons::IconIndex index) const;
//! \copydoc CValueObject::asQVariant
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
@@ -126,24 +126,18 @@ namespace BlackMisc
}
//! Icon for given index
static const CIcon &iconForIndex(CIcons::IconIndexes index)
static const CIcon &iconForIndex(CIcons::IconIndex index)
{
// remark, find by is copy, need reference of icon
int s = allIcons().size();
for (int i = 0; i < s; i++)
{
if (allIcons()[i].getIndex() == index)
{
return allIcons()[i];
}
}
auto foundRange = allIcons().findBy(&CIcon::getIndex, index);
if (!foundRange.isEmpty()) { return foundRange.front(); }
Q_ASSERT_X(false, "iconForIndex", "Missing index");
return iconForIndex(CIcons::StandardIconUnknown16);
}
//! Icon for given index
static const CIcon &iconForIndex(int index) {
return iconForIndex(static_cast<CIcons::IconIndexes>(index));
static const CIcon &iconForIndex(int index)
{
return iconForIndex(static_cast<CIcons::IconIndex>(index));
}
};

View File

@@ -19,14 +19,13 @@ namespace BlackMisc
//! Standard icons
class CIcons
{
private:
//! Constructor, use class static only
CIcons();
public:
//! Constructor, use class static only
CIcons() = delete;
//! Index for each icon, allows to send them via DBus, efficiently store them, etc.
enum IconIndexes
enum IconIndex
{
NotSet,
StandardIconInfo16,
@@ -606,7 +605,7 @@ namespace BlackMisc
// -------------------------------------------------------------
//! Pixmap by given index
static const QPixmap &pixmapByIndex(IconIndexes index)
static const QPixmap &pixmapByIndex(IconIndex index)
{
switch (index)
{
@@ -687,7 +686,7 @@ namespace BlackMisc
}
//! Pixmap by given index rotated
static QPixmap pixmapByIndex(IconIndexes index, int rotateDegrees)
static QPixmap pixmapByIndex(IconIndex index, int rotateDegrees)
{
const QPixmap original = pixmapByIndex(index);
if (rotateDegrees == 0) return original;

View File

@@ -154,7 +154,7 @@ namespace BlackMisc
case IndexIcon:
if (variant.canConvert<int>())
{
CIcons::IconIndexes index = static_cast<CIcons::IconIndexes>(variant.toInt());
CIcons::IconIndex index = static_cast<CIcons::IconIndex>(variant.toInt());
this->m_icon = CIconList::iconForIndex(index);
}
else

View File

@@ -126,7 +126,7 @@ namespace BlackSimPlugin
// COM Settings, transponder, SB3
FSUIPC_Read(0x7b91, 1, &xpdrModeSb3Raw, &dwResult) &&
FSUIPC_Read(0x7b92, 1, &xpdrIdentSb3Raw, &dwResult) &&
FSUIPC_Read(0x7b93, 1, &xpdrIdentSb3Raw, &dwResult) &&
// Speeds, situation
FSUIPC_Read(0x02b4, 4, &groundspeedRaw, &dwResult) &&