From fc3a36512e28535ed6df776b9ff31c0d86dc4273 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 23 Mar 2017 03:16:25 +0100 Subject: [PATCH] refs #911, paste support in forms * added paste icon * base class utility functions * implemented paste for livery, airline and aircraft ICAO --- src/blackgui/editors/aircrafticaoform.cpp | 24 +- src/blackgui/editors/aircrafticaoform.h | 4 + src/blackgui/editors/aircrafticaoform.ui | 471 ++++++++++++---------- src/blackgui/editors/airlineicaoform.cpp | 25 +- src/blackgui/editors/airlineicaoform.h | 4 + src/blackgui/editors/airlineicaoform.ui | 21 +- src/blackgui/editors/distributorform.cpp | 12 +- src/blackgui/editors/distributorform.h | 7 +- src/blackgui/editors/distributorform.ui | 2 +- src/blackgui/editors/form.cpp | 18 +- src/blackgui/editors/form.h | 9 +- src/blackgui/editors/liveryform.cpp | 22 +- src/blackgui/editors/liveryform.h | 4 + src/blackgui/editors/liveryform.ui | 167 ++++---- 14 files changed, 482 insertions(+), 308 deletions(-) diff --git a/src/blackgui/editors/aircrafticaoform.cpp b/src/blackgui/editors/aircrafticaoform.cpp index 37ce1cb2f..3ca2f9097 100644 --- a/src/blackgui/editors/aircrafticaoform.cpp +++ b/src/blackgui/editors/aircrafticaoform.cpp @@ -45,7 +45,7 @@ namespace BlackGui { ui->setupUi(this); this->setFocusProxy(ui->le_Id); - ui->lai_id->set(CIcons::appAircraftIcao16(), "Id:"); + ui->lai_Id->set(CIcons::appAircraftIcao16(), "Id:"); ui->le_Updated->setReadOnly(true); ui->le_Id->setValidator(new QIntValidator(0, 999999, ui->le_Id)); ui->aircraft_Selector->displayWithIcaoDescription(false); @@ -54,8 +54,9 @@ namespace BlackGui // Id connect(ui->le_Id, &QLineEdit::returnPressed, this, &CAircraftIcaoForm::ps_idEntered); - // drag and drop + // drag and drop, pasted connect(ui->drop_DropData, &CDropSite::droppedValueObject, this, &CAircraftIcaoForm::ps_droppedCode); + connect(ui->tb_Paste, &QToolButton::clicked, this, &CAircraftIcaoForm::ps_pasted); ui->drop_DropData->setInfoText(""); ui->drop_DropData->setAcceptedMetaTypeIds({ qMetaTypeId(), qMetaTypeId()}); } @@ -89,6 +90,23 @@ namespace BlackGui return true; } + void CAircraftIcaoForm::jsonPasted(const QString &json) + { + try + { + CAircraftIcaoCodeList icaos; + icaos.convertFromJson(Json::jsonObjectFromString(json)); + if (!icaos.isEmpty()) + { + this->setValue(icaos.front()); + } + } + catch (const CJsonException &ex) + { + Q_UNUSED(ex); + } + } + CAircraftIcaoCode CAircraftIcaoForm::getValue() const { CAircraftIcaoCode icao(ui->aircraft_Selector->getAircraftIcao()); @@ -159,6 +177,7 @@ namespace BlackGui ui->le_Family->setReadOnly(readOnly); ui->le_Iata->setReadOnly(readOnly); ui->le_Id->setReadOnly(readOnly); + ui->tb_Paste->setVisible(!readOnly); CGuiUtility::checkBoxReadOnly(ui->cb_Legacy, readOnly); CGuiUtility::checkBoxReadOnly(ui->cb_Military, readOnly); @@ -173,6 +192,7 @@ namespace BlackGui void CAircraftIcaoForm::setSelectOnly() { this->setReadOnly(true); + ui->tb_Paste->setVisible(true); ui->aircraft_Selector->setReadOnly(false); ui->le_Id->setReadOnly(false); ui->drop_DropData->setVisible(true); diff --git a/src/blackgui/editors/aircrafticaoform.h b/src/blackgui/editors/aircrafticaoform.h index 98feebde6..0a3a15583 100644 --- a/src/blackgui/editors/aircrafticaoform.h +++ b/src/blackgui/editors/aircrafticaoform.h @@ -69,6 +69,10 @@ namespace BlackGui //! Set value bool setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao); + protected: + //! \copydoc CForm::jsonPasted + virtual void jsonPasted(const QString &json) override; + private slots: //! Variant has been dropped void ps_droppedCode(const BlackMisc::CVariant &variantDropped); diff --git a/src/blackgui/editors/aircrafticaoform.ui b/src/blackgui/editors/aircrafticaoform.ui index 048c7a591..0af1faf87 100644 --- a/src/blackgui/editors/aircrafticaoform.ui +++ b/src/blackgui/editors/aircrafticaoform.ui @@ -41,90 +41,6 @@ Aircraft ICAO - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - Qt::StrongFocus - - - - - - - - 0 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - - - 8 - - - - - 9 - - - - - Unspecified - - - - - - - @@ -147,10 +63,19 @@ - - - - Qt::StrongFocus + + + + + 20 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised @@ -242,130 +167,6 @@ - - - - - 20 - 0 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - - IATA/family: - - - - - - - - 75 - 16777215 - - - - true - - - Id - - - - - - - e.g. Boeing, Airbus - - - - - - - Model: - - - le_ModelDescription - - - - - - - Misc.: - - - - - - - Type / Engine / Engine count - - - Comb. type: - - - - - - - Aircraft model - - - - - - - true - - - Last updated - - - - - - - Last updated: - - - le_Updated - - - - - - - Design./Rank: - - - - - - - Manufacturer: - - - le_Manufacturer - - - - - - - Drop data here - - - @@ -407,6 +208,247 @@ + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::StrongFocus + + + + + + + + 0 + + + + + 1 + + + + + 2 + + + + + 3 + + + + + 4 + + + + + 5 + + + + + 6 + + + + + 7 + + + + + 8 + + + + + 9 + + + + + Unspecified + + + + + + + + + + + Qt::StrongFocus + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 75 + 16777215 + + + + true + + + Id + + + + + + + ... + + + + :/diagona/icons/diagona/icons/clipboard-paste.png:/diagona/icons/diagona/icons/clipboard-paste.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + IATA/family: + + + + + + + Model: + + + le_ModelDescription + + + + + + + e.g. Boeing, Airbus + + + + + + + Aircraft model + + + + + + + true + + + Last updated + + + + + + + Misc.: + + + + + + + Type / Engine / Engine count + + + Comb. type: + + + + + + + Manufacturer: + + + le_Manufacturer + + + + + + + Last updated: + + + le_Updated + + + + + + + Design./Rank: + + + + + + + Drop data here + + + @@ -444,7 +486,6 @@ - le_Id aircraft_Selector cb_Rank le_Iata @@ -458,6 +499,8 @@ cb_Military le_Updated - + + + diff --git a/src/blackgui/editors/airlineicaoform.cpp b/src/blackgui/editors/airlineicaoform.cpp index 93beaa3c9..f8350636d 100644 --- a/src/blackgui/editors/airlineicaoform.cpp +++ b/src/blackgui/editors/airlineicaoform.cpp @@ -51,7 +51,8 @@ namespace BlackGui // Id connect(ui->le_Id, &QLineEdit::returnPressed, this, &CAirlineIcaoForm::ps_idEntered); - // drag and drop + // drag and drop, paste + connect(ui->tb_Paste, &QToolButton::clicked, this, &CAirlineIcaoForm::ps_pasted); connect(ui->drop_DropData, &CDropSite::droppedValueObject, this, &CAirlineIcaoForm::ps_droppedCode); ui->drop_DropData->setInfoText(""); ui->drop_DropData->setAcceptedMetaTypeIds({ qMetaTypeId(), qMetaTypeId()}); @@ -75,6 +76,9 @@ namespace BlackGui ui->country_Selector->setCountry(icao.getCountry()); ui->lbl_AirlineIcon->setPixmap(icao.toPixmap()); + // sometimes artefacts when icon is displayed + this->repaint(); + if (this->m_originalCode.hasCompleteData()) { emit airlineChanged(this->m_originalCode); @@ -125,6 +129,7 @@ namespace BlackGui ui->le_TelephonyDesignator->setReadOnly(readOnly); ui->country_Selector->setReadOnly(readOnly); ui->drop_DropData->setVisible(!readOnly); + ui->tb_Paste->setVisible(!readOnly); CGuiUtility::checkBoxReadOnly(ui->cb_Va, readOnly); CGuiUtility::checkBoxReadOnly(ui->cb_Military, readOnly); @@ -137,6 +142,7 @@ namespace BlackGui ui->selector_AirlineDesignator->setReadOnly(false); ui->selector_AirlineName->setReadOnly(false); ui->drop_DropData->setVisible(true); + ui->tb_Paste->setVisible(true); } void CAirlineIcaoForm::clear() @@ -149,6 +155,23 @@ namespace BlackGui this->setValue(m_originalCode); } + void CAirlineIcaoForm::jsonPasted(const QString &json) + { + try + { + CAirlineIcaoCodeList icaos; + icaos.convertFromJson(Json::jsonObjectFromString(json)); + if (!icaos.isEmpty()) + { + this->setValue(icaos.front()); + } + } + catch (const CJsonException &ex) + { + Q_UNUSED(ex); + } + } + void CAirlineIcaoForm::ps_droppedCode(const BlackMisc::CVariant &variantDropped) { CAirlineIcaoCode icao; diff --git a/src/blackgui/editors/airlineicaoform.h b/src/blackgui/editors/airlineicaoform.h index 2bad6bbd8..1f8e6493e 100644 --- a/src/blackgui/editors/airlineicaoform.h +++ b/src/blackgui/editors/airlineicaoform.h @@ -73,6 +73,10 @@ namespace BlackGui //! Airline has been changed void airlineChanged(const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcao); + protected: + //! \copydoc CForm::jsonPasted + virtual void jsonPasted(const QString &json) override; + private slots: //! Variant has been dropped void ps_droppedCode(const BlackMisc::CVariant &variantDropped); diff --git a/src/blackgui/editors/airlineicaoform.ui b/src/blackgui/editors/airlineicaoform.ui index 76ce25d1c..286dca7ed 100644 --- a/src/blackgui/editors/airlineicaoform.ui +++ b/src/blackgui/editors/airlineicaoform.ui @@ -6,8 +6,8 @@ 0 0 - 233 - 205 + 243 + 206 @@ -107,6 +107,17 @@ + + + + ... + + + + :/diagona/icons/diagona/icons/clipboard-paste.png:/diagona/icons/diagona/icons/clipboard-paste.png + + + @@ -205,7 +216,7 @@ - Last updated + Last updated: le_Updated @@ -310,6 +321,8 @@ country_Selector le_Updated - + + + diff --git a/src/blackgui/editors/distributorform.cpp b/src/blackgui/editors/distributorform.cpp index a2386fcaa..c1979f6e0 100644 --- a/src/blackgui/editors/distributorform.cpp +++ b/src/blackgui/editors/distributorform.cpp @@ -62,6 +62,11 @@ namespace BlackGui return true; } + void CDistributorForm::jsonPasted(const QString &json) + { + Q_UNUSED(json); + } + CDistributor CDistributorForm::getValue() const { CDistributor distributor(ui->distributor_Selector->getDistributor()); @@ -126,9 +131,9 @@ namespace BlackGui } else if (variantDropped.canConvert()) { - CDistributorList icaoList(variantDropped.value()); - if (icaoList.isEmpty()) { return; } - distributor = icaoList.front(); + const CDistributorList icaoList(variantDropped.value()); + if (icaoList.isEmpty()) { return; } + distributor = icaoList.front(); } else { @@ -136,6 +141,5 @@ namespace BlackGui } this->setValue(distributor); } - } // ns } // ns diff --git a/src/blackgui/editors/distributorform.h b/src/blackgui/editors/distributorform.h index ec3e567f8..171f70d35 100644 --- a/src/blackgui/editors/distributorform.h +++ b/src/blackgui/editors/distributorform.h @@ -41,7 +41,7 @@ namespace BlackGui explicit CDistributorForm(QWidget *parent = nullptr); //! Destructor - ~CDistributorForm(); + virtual ~CDistributorForm(); //! Get value BlackMisc::Simulation::CDistributor getValue() const; @@ -66,6 +66,10 @@ namespace BlackGui //! Set value bool setValue(const BlackMisc::Simulation::CDistributor &distributor = BlackMisc::Simulation::CDistributor()); + protected: + //! \copydoc CForm::jsonPasted + virtual void jsonPasted(const QString &json) override; + private slots: //! Variant has been dropped void ps_droppedCode(const BlackMisc::CVariant &variantDropped); @@ -74,7 +78,6 @@ namespace BlackGui QScopedPointer ui; bool m_readOnly = false; }; - } // ns } //ns diff --git a/src/blackgui/editors/distributorform.ui b/src/blackgui/editors/distributorform.ui index 3ac12727d..e641d267e 100644 --- a/src/blackgui/editors/distributorform.ui +++ b/src/blackgui/editors/distributorform.ui @@ -72,7 +72,7 @@ - Last updated + Last updated: diff --git a/src/blackgui/editors/form.cpp b/src/blackgui/editors/form.cpp index 499b60588..911f318cc 100644 --- a/src/blackgui/editors/form.cpp +++ b/src/blackgui/editors/form.cpp @@ -8,6 +8,9 @@ */ #include "blackgui/editors/form.h" +#include +#include +#include using namespace BlackMisc; using namespace BlackMisc::Network; @@ -17,7 +20,7 @@ namespace BlackGui namespace Editors { CForm::CForm(QWidget *parent) : COverlayMessagesFrame(parent) - { } + { } CForm::~CForm() { } @@ -37,9 +40,22 @@ namespace BlackGui return this->m_swiftDbUser.get(); } + void CForm::jsonPasted(const QString &json) + { + Q_UNUSED(json); + } + void CForm::ps_userChanged() { // void } + + void CForm::ps_pasted() + { + if (!QApplication::clipboard()) { return; } + const QString data = QApplication::clipboard()->text(); + if (!Json::looksLikeSwiftJson(data)) { return; } + this->jsonPasted(data); + } } // ns } // ns diff --git a/src/blackgui/editors/form.h b/src/blackgui/editors/form.h index a8086af85..30d95fe52 100644 --- a/src/blackgui/editors/form.h +++ b/src/blackgui/editors/form.h @@ -37,7 +37,7 @@ namespace BlackGui explicit CForm(QWidget *parent = nullptr); //! Destructor - ~CForm(); + virtual ~CForm(); //! Set editable virtual void setReadOnly(bool readOnly) = 0; @@ -56,12 +56,19 @@ namespace BlackGui BlackMisc::Network::CAuthenticatedUser getSwiftDbUser() const; protected: + //! JSON string has been pasted + //! \remark The JSON string has been pre-checked + virtual void jsonPasted(const QString &json); + bool m_readOnly = false; //!< read only BlackMisc::CDataReadOnly m_swiftDbUser {this, &CForm::ps_userChanged}; //!< authenticated user protected slots: //! User has been changed virtual void ps_userChanged(); + + //! Pasted from clipboard + void ps_pasted(); }; } // ns } // ns diff --git a/src/blackgui/editors/liveryform.cpp b/src/blackgui/editors/liveryform.cpp index 2d2015ec9..dd6f5205a 100644 --- a/src/blackgui/editors/liveryform.cpp +++ b/src/blackgui/editors/liveryform.cpp @@ -52,7 +52,8 @@ namespace BlackGui // selector connect(ui->comp_LiverySelector, &CDbLiverySelectorComponent::changedLivery, this, &CLiveryForm::setValue); - // drag and drop + // drag and drop, paste + connect(ui->tb_Paste, &QToolButton::clicked, this, &CLiveryForm::ps_pasted); connect(ui->drop_DropData, &CDropSite::droppedValueObject, this, &CLiveryForm::ps_droppedLivery); ui->drop_DropData->setInfoText(""); ui->drop_DropData->setAcceptedMetaTypeIds({ qMetaTypeId(), qMetaTypeId()}); @@ -112,6 +113,23 @@ namespace BlackGui return true; } + void CLiveryForm::jsonPasted(const QString &json) + { + try + { + CLiveryList liveries; + liveries.convertFromJson(Json::jsonObjectFromString(json)); + if (!liveries.isEmpty()) + { + this->setValue(liveries.front()); + } + } + catch (const CJsonException &ex) + { + Q_UNUSED(ex); + } + } + CStatusMessageList CLiveryForm::validate(bool withNestedForms) const { CLivery livery(getValue()); @@ -161,6 +179,7 @@ namespace BlackGui ui->pb_SearchColor->setVisible(!readOnly); ui->pb_TempLivery->setVisible(!readOnly); ui->drop_DropData->setVisible(!readOnly); + ui->tb_Paste->setVisible(!readOnly); CGuiUtility::checkBoxReadOnly(ui->cb_Military, readOnly); } @@ -173,6 +192,7 @@ namespace BlackGui ui->drop_DropData->setVisible(true); ui->pb_SearchColor->setVisible(true); ui->pb_TempLivery->setVisible(true); + ui->tb_Paste->setVisible(true); } void CLiveryForm::clear() diff --git a/src/blackgui/editors/liveryform.h b/src/blackgui/editors/liveryform.h index bde11da66..db58bdaf3 100644 --- a/src/blackgui/editors/liveryform.h +++ b/src/blackgui/editors/liveryform.h @@ -76,6 +76,10 @@ namespace BlackGui //! Value bool setValue(const BlackMisc::Aviation::CLivery &livery); + protected: + //! \copydoc CForm::jsonPasted + virtual void jsonPasted(const QString &json) override; + private slots: //! Livery dropped void ps_droppedLivery(const BlackMisc::CVariant &variantDropped); diff --git a/src/blackgui/editors/liveryform.ui b/src/blackgui/editors/liveryform.ui index 4d05acc38..6cf050077 100644 --- a/src/blackgui/editors/liveryform.ui +++ b/src/blackgui/editors/liveryform.ui @@ -34,7 +34,7 @@ Livery - + @@ -45,6 +45,13 @@ + + + + Fuselage/Tail: + + + @@ -55,6 +62,13 @@ + + + + Code: + + + @@ -68,52 +82,7 @@ - - - - Code: - - - - - - - Fuselage/Tail: - - - - - - - true - - - - - - - Livery description - - - - - - - Drop data here - - - - - - - Military livery - - - Mil. - - - - + <html><head/><body><p>set a 'no color' livery, allowing to create a<br/>temp. DB entry which will later be specified.</p></body></html> @@ -123,7 +92,64 @@ - + + + + Livery description + + + + + + + Drop data here + + + + + + + Military livery + + + Mil. + + + + + + + true + + + + + + + find a color livery + + + search color + + + + + + + + 0 + 225 + + + + Qt::StrongFocus + + + + + + + @@ -139,23 +165,7 @@ - - - - - - - - 0 - 225 - - - - Qt::StrongFocus - - - - + @@ -215,23 +225,24 @@ - - - - find a color livery - - - search color - - - - + Qt::StrongFocus + + + + ... + + + + :/diagona/icons/diagona/icons/clipboard-paste.png:/diagona/icons/diagona/icons/clipboard-paste.png + + + @@ -285,6 +296,8 @@ color_Tail le_Updated - + + +