mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-23 22:15:37 +08:00
follow up of refs #643, allow to display icon in overlay window
* some optimization to check if icon is available * menus for context menu * allow to display icon/image in overlay window
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "aircraftmodelmenus.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
#include "blackmisc/simulation/aircraftmodelutils.h"
|
||||
#include <QDesktopServices>
|
||||
|
||||
@@ -44,15 +45,32 @@ namespace BlackGui
|
||||
return mv->selectedObjects();
|
||||
}
|
||||
|
||||
CShowSimulatorFileMenu::CShowSimulatorFileMenu(CAircraftModelView *modelView, COverlayMessagesFrame *messageFrame, bool separator) :
|
||||
IAircraftModelViewMenu(modelView, separator), m_messageFrame(messageFrame)
|
||||
{ }
|
||||
|
||||
void CShowSimulatorFileMenu::customMenu(QMenu &menu) const
|
||||
{
|
||||
CAircraftModelView *mv = modelView();
|
||||
Q_ASSERT_X(mv, Q_FUNC_INFO, "no view");
|
||||
|
||||
if (mv->hasSelection())
|
||||
if (mv->hasSingleSelectedRow())
|
||||
{
|
||||
this->addSeparator(menu);
|
||||
menu.addAction(CIcons::text16(), "Open simulator file", this, &CShowSimulatorFileMenu::ps_showSimulatorFile);
|
||||
const CAircraftModel model(mv->selectedObject());
|
||||
if (model.hasFileName() || (!model.getIconPath().isEmpty() && this->m_messageFrame))
|
||||
{
|
||||
this->addSeparator(menu);
|
||||
if (this->m_messageFrame)
|
||||
{
|
||||
const CAircraftModel model(mv->selectedObject());
|
||||
if (!model.getIconPath().isEmpty())
|
||||
{
|
||||
this->addSeparator(menu);
|
||||
menu.addAction(CIcons::appAircraft16(), "Display icon", this, &CShowSimulatorFileMenu::ps_displayIcon);
|
||||
}
|
||||
}
|
||||
menu.addAction(CIcons::text16(), "Open simulator file", this, &CShowSimulatorFileMenu::ps_showSimulatorFile);
|
||||
}
|
||||
}
|
||||
this->nestedCustomMenu(menu);
|
||||
}
|
||||
@@ -60,21 +78,32 @@ namespace BlackGui
|
||||
void CShowSimulatorFileMenu::ps_showSimulatorFile() const
|
||||
{
|
||||
const CAircraftModelView *mv = modelView();
|
||||
if (!mv->hasSelection()) { return; }
|
||||
const CAircraftModelList models(getSelectedAircraftModels().findWithFileName());
|
||||
if (models.isEmpty()) { return; }
|
||||
int trails = 0;
|
||||
|
||||
for (const CAircraftModel &model : models)
|
||||
if (!mv->hasSingleSelectedRow()) { return; }
|
||||
const CAircraftModel model(mv->selectedObject());
|
||||
if (!model.hasFileName()) { return; }
|
||||
if (QFile::exists(model.getFileName()))
|
||||
{
|
||||
trails++;
|
||||
if (QFile::exists(model.getFileName()))
|
||||
{
|
||||
const QString url("file:///" + model.getFileName());
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
break;
|
||||
}
|
||||
if (trails > 10) { break; }
|
||||
const QString url("file:///" + model.getFileName());
|
||||
QDesktopServices::openUrl(QUrl(url));
|
||||
}
|
||||
}
|
||||
|
||||
void CShowSimulatorFileMenu::ps_displayIcon()
|
||||
{
|
||||
const CAircraftModelView *mv = modelView();
|
||||
if (!mv->hasSingleSelectedRow()) { return; }
|
||||
const CAircraftModel model(mv->selectedObject());
|
||||
if (model.getIconPath().isEmpty()) { return; }
|
||||
CStatusMessage msg;
|
||||
const CPixmap pm(model.loadIcon(msg));
|
||||
if (msg.isSuccess())
|
||||
{
|
||||
this->m_messageFrame->showOverlayImage(pm);
|
||||
}
|
||||
else
|
||||
{
|
||||
msg.setCategories(getLogCategories());
|
||||
CLogMessage::preformatted(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,6 +164,14 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CMergeWithDbDataMenu::addSeparator(QMenu &menu) const
|
||||
{
|
||||
// when the menu before us is a DB menu, we ignore the separator
|
||||
if (!this->m_separator) { return; }
|
||||
if (this->previousMenuItemContains("DB", menu)) { return; }
|
||||
IAircraftModelViewMenu::addSeparator(menu);
|
||||
}
|
||||
|
||||
IModelsSetable *CMergeWithDbDataMenu::modelsTargetSetable() const
|
||||
{
|
||||
return qobject_cast<IModelsSetable *>(this->m_modelsTarget);
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "menudelegate.h"
|
||||
#include "blackgui/views/aircraftmodelview.h"
|
||||
#include "blackgui/overlaymessagesframe.h"
|
||||
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
|
||||
#include "blackmisc/simulation/fscommon/vpilotrulesreader.h"
|
||||
#include <QMenu>
|
||||
@@ -48,14 +49,17 @@ namespace BlackGui
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
using IAircraftModelViewMenu::IAircraftModelViewMenu;
|
||||
CShowSimulatorFileMenu(BlackGui::Views::CAircraftModelView *modelView, BlackGui::COverlayMessagesFrame *messageFrame, bool separator = true);
|
||||
|
||||
//! \copydoc IMenuDelegate::customMenu
|
||||
virtual void customMenu(QMenu &menu) const override;
|
||||
|
||||
private slots:
|
||||
//! Open simulator file
|
||||
void ps_showSimulatorFile() const;
|
||||
void ps_showSimulatorFile() const; //!< simulator file
|
||||
void ps_displayIcon(); //!< aircraft icon if any
|
||||
|
||||
private:
|
||||
BlackGui::COverlayMessagesFrame *m_messageFrame = nullptr;
|
||||
};
|
||||
|
||||
//! Merge with DB data
|
||||
@@ -77,10 +81,14 @@ namespace BlackGui
|
||||
void ps_mergeData();
|
||||
void ps_mergeSelectedData();
|
||||
|
||||
protected:
|
||||
//! \copydoc IMenuDelegate::addSeparator
|
||||
virtual void addSeparator(QMenu &menu) const override;
|
||||
|
||||
private:
|
||||
BlackMisc::Simulation::IModelsSetable *modelsTargetSetable() const;
|
||||
BlackMisc::Simulation::IModelsSetable *modelsTargetSetable() const;
|
||||
BlackMisc::Simulation::IModelsUpdatable *modelsTargetUpdatable() const;
|
||||
QObject *m_modelsTarget = nullptr; //!< optional target for setting/updating the models
|
||||
QObject *m_modelsTarget = nullptr; //!< optional target for setting/updating the models
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
#ifndef BLACKGUI_MENUS_MENUDELEGATE_H
|
||||
#define BLACKGUI_MENUS_MENUDELEGATE_H
|
||||
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
#include <QMenu>
|
||||
#include <QObject>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Menus
|
||||
@@ -37,6 +40,13 @@ namespace BlackGui
|
||||
//! Destructor
|
||||
virtual ~IMenuDelegate() {}
|
||||
|
||||
//! Log categories
|
||||
const CLogCategoryList &getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats({CLogCategory::guiComponent()});
|
||||
return cats;
|
||||
}
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IMenuDelegate(QWidget *parent = nullptr, bool separator = false) :
|
||||
@@ -50,12 +60,20 @@ namespace BlackGui
|
||||
}
|
||||
|
||||
//! Add separator
|
||||
void addSeparator(QMenu &menu) const
|
||||
virtual void addSeparator(QMenu &menu) const
|
||||
{
|
||||
if (!m_separator || menu.isEmpty()) { return; }
|
||||
menu.addSeparator();
|
||||
}
|
||||
|
||||
//! Does the previous (menu) item contain string?
|
||||
bool previousMenuItemContains(const QString &str, const QMenu &menu, Qt::CaseSensitivity cs = Qt::CaseSensitive) const
|
||||
{
|
||||
if (menu.isEmpty() || str.isEmpty()) { return false; }
|
||||
const QString t(menu.actions().last()->text());
|
||||
return t.contains(str, cs);
|
||||
}
|
||||
|
||||
IMenuDelegate *m_nestedDelegate = nullptr; //!< nested delegate if any
|
||||
bool m_separator = false; //!< at end, terminate with separator
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user