refs #768, made color search a QFrame

* color search is a simple QFrame
* the dialog now uses this QFrame color search
* Rational: Color search can also be used in other components
This commit is contained in:
Klaus Basan
2016-10-17 03:05:03 +02:00
parent 4c6bb6e3fd
commit 1152502721
6 changed files with 221 additions and 90 deletions

View File

@@ -21,33 +21,31 @@ namespace BlackGui
namespace Components
{
CDbLiveryColorSearch::CDbLiveryColorSearch(QWidget *parent) :
QDialog(parent),
QFrame(parent),
ui(new Ui::CDbLiveryColorSearch)
{
ui->setupUi(this);
connect(this, &CDbLiveryColorSearch::accepted, this, &CDbLiveryColorSearch::ps_onAccepted);
this->setFocusProxy(ui->comp_FuselageSelector);
}
CDbLiveryColorSearch::~CDbLiveryColorSearch()
{ }
BlackMisc::Aviation::CLivery CDbLiveryColorSearch::getLivery() const
CLivery CDbLiveryColorSearch::getLivery() const
{
return this->m_foundLivery;
}
void CDbLiveryColorSearch::ps_onAccepted()
{
if (!sGui || !sGui->hasWebDataServices())
{
this->m_foundLivery = CLivery();
return;
}
const CRgbColor fuselage = ui->comp_FuselageSelector->getColor();
const CRgbColor tail = ui->comp_TailSelector->getColor();
const CLiveryList liveries(sGui->getWebDataServices()->getLiveries());
this->m_foundLivery = liveries.findClosestColorLiveryOrDefault(fuselage, tail);
return liveries.findClosestColorLiveryOrDefault(fuselage, tail);
}
void CDbLiveryColorSearch::presetColorLivery(const CLivery &livery)
{
if (livery.isColorLivery())
{
ui->comp_FuselageSelector->setColor(livery.getColorFuselage());
ui->comp_TailSelector->setColor(livery.getColorTail());
}
}
} // ns
} // ns

View File

@@ -13,7 +13,7 @@
#define BLACKGUI_COMPONENTS_DBLIVERYCOLORSEARCH_H
#include "blackmisc/aviation/livery.h"
#include <QDialog>
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CDbLiveryColorSearch; }
@@ -22,9 +22,9 @@ namespace BlackGui
namespace Components
{
/*!
* Search for best color livery
* Search for best matching color livery
*/
class CDbLiveryColorSearch : public QDialog
class CDbLiveryColorSearch : public QFrame
{
Q_OBJECT
@@ -38,11 +38,8 @@ namespace BlackGui
//! Found livery if any, otherwise default
BlackMisc::Aviation::CLivery getLivery() const;
private:
//! Dialog has been accepted
void ps_onAccepted();
BlackMisc::Aviation::CLivery m_foundLivery; //!< lat livery found
//! Preset colors
void presetColorLivery(const BlackMisc::Aviation::CLivery &livery);
private:
QScopedPointer<Ui::CDbLiveryColorSearch> ui;

View File

@@ -1,49 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDbLiveryColorSearch</class>
<widget class="QDialog" name="CDbLiveryColorSearch">
<widget class="QFrame" name="CDbLiveryColorSearch">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>237</width>
<height>80</height>
<width>171</width>
<height>52</height>
</rect>
</property>
<property name="windowTitle">
<string>Search color livery</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="1">
<widget class="QDialogButtonBox" name="bb_LiveryColorSearch">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="BlackGui::Components::CColorSelector" name="comp_FuselageSelector">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="BlackGui::Components::CColorSelector" name="comp_TailSelector">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Fuselage">
<property name="text">
@@ -58,6 +28,26 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="BlackGui::Components::CColorSelector" name="comp_FuselageSelector">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="BlackGui::Components::CColorSelector" name="comp_TailSelector">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@@ -69,38 +59,5 @@
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>bb_LiveryColorSearch</sender>
<signal>accepted()</signal>
<receiver>CDbLiveryColorSearch</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bb_LiveryColorSearch</sender>
<signal>rejected()</signal>
<receiver>CDbLiveryColorSearch</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "dbliverycolorsearchdialog.h"
#include "blackgui/guiapplication.h"
#include "blackcore/webdataservices.h"
#include "blackmisc/aviation/liverylist.h"
#include "ui_dbliverycolorsearchdialog.h"
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
namespace BlackGui
{
namespace Components
{
CDbLiveryColorSearchDialog::CDbLiveryColorSearchDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::CDbLiveryColorSearchDialog)
{
ui->setupUi(this);
connect(this, &CDbLiveryColorSearchDialog::accepted, this, &CDbLiveryColorSearchDialog::ps_onAccepted);
}
CDbLiveryColorSearchDialog::~CDbLiveryColorSearchDialog()
{ }
const CLivery &CDbLiveryColorSearchDialog::getLivery() const
{
return this->m_foundLivery;
}
void CDbLiveryColorSearchDialog::ps_onAccepted()
{
this->m_foundLivery = ui->comp_LiverySearch->getLivery();
}
} // ns
} // ns

View File

@@ -0,0 +1,53 @@
/* Copyright (C) 2016
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_DBLIVERYCOLORSEARCHDIALOG_H
#define BLACKGUI_COMPONENTS_DBLIVERYCOLORSEARCHDIALOG_H
#include "blackmisc/aviation/livery.h"
#include <QDialog>
#include <QScopedPointer>
namespace Ui { class CDbLiveryColorSearchDialog; }
namespace BlackGui
{
namespace Components
{
/*!
* Search for best matching color livery
*/
class CDbLiveryColorSearchDialog : public QDialog
{
Q_OBJECT
public:
//! Constructor
explicit CDbLiveryColorSearchDialog(QWidget *parent = nullptr);
//! Destructor
~CDbLiveryColorSearchDialog();
//! Found livery if any, otherwise default
const BlackMisc::Aviation::CLivery &getLivery() const;
private:
//! Dialog has been accepted
void ps_onAccepted();
BlackMisc::Aviation::CLivery m_foundLivery; //!< last livery found
private:
QScopedPointer<Ui::CDbLiveryColorSearchDialog> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDbLiveryColorSearchDialog</class>
<widget class="QDialog" name="CDbLiveryColorSearchDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>237</width>
<height>80</height>
</rect>
</property>
<property name="windowTitle">
<string>Search color livery</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="BlackGui::Components::CDbLiveryColorSearch" name="comp_LiverySearch">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="bb_LiveryColorSearch">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CDbLiveryColorSearch</class>
<extends>QFrame</extends>
<header>blackgui/components/dbliverycolorsearch.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>bb_LiveryColorSearch</sender>
<signal>accepted()</signal>
<receiver>CDbLiveryColorSearchDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>bb_LiveryColorSearch</sender>
<signal>rejected()</signal>
<receiver>CDbLiveryColorSearchDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>