225 lines
5.4 KiB
C++
Executable File
225 lines
5.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Bottom Button Box for Dialogs which need actions
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2016-08-17
|
|
*/
|
|
|
|
#include "lts_dialog_button_box.h"
|
|
#include "ui_lts_dialog_button_box.h"
|
|
|
|
#include "lts_message_dialog.h"
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <QMenu>
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
LtsDialogButtonBox::LtsDialogButtonBox(QWidget *parent)
|
|
: QWidget(parent)
|
|
, m_isTablet(LtsSessionData::LtsSessionData::getInstance()->isTablet())
|
|
, m_ui(new Ui::LtsDialogButtonBox)
|
|
{
|
|
m_ui->setupUi(this);
|
|
_setVisibilityForAll(false); // hide all buttons
|
|
|
|
// Btn 'Library'
|
|
QMenu *libraryMenu = new QMenu(m_ui->pbLibrary);
|
|
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_load.svg")),
|
|
tr("Load"), this, &LtsDialogButtonBox::signalLibraryLoadClicked);
|
|
libraryMenu->addAction(QIcon(QLatin1String(":/style/library_save.svg")),
|
|
tr("Save"), this, &LtsDialogButtonBox::signalLibrarySaveClicked);
|
|
m_ui->pbLibrary->setMenu(libraryMenu);
|
|
|
|
// exceptions for call above:
|
|
m_ui->pbOk->setVisible(true); // c LtsDialog's impl 2 c y !
|
|
m_ui->pbClose->setVisible(true); // s.a.a.
|
|
// no help file name set = no help button ! => m_ui->pbHelp->setVisible(true); // must be explicitly hidden for dialogs without help content
|
|
}
|
|
|
|
|
|
LtsDialogButtonBox::~LtsDialogButtonBox()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::_setVisibilityForAll(bool visible)
|
|
{
|
|
const auto buttons = findChildren<QPushButton *>();
|
|
for (QPushButton *button : buttons)
|
|
button->setVisible(visible);
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setText(DialogButton button, const QString &text)
|
|
{
|
|
// TODO: check if setText was called by a 'retranslate' method, if not debug msg !
|
|
|
|
QPushButton *btn = getButton(button);
|
|
|
|
if (btn)
|
|
btn->setText(text);
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setToolTip(DialogButton button, const QString &text)
|
|
{
|
|
QPushButton *btn = getButton(button);
|
|
|
|
if (btn)
|
|
btn->setToolTip(text);
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setIcon(DialogButton button, const QIcon &icon)
|
|
{
|
|
QPushButton *btn = getButton(button);
|
|
|
|
if (btn)
|
|
btn->setIcon(icon);
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setMenu(DialogButton button, QMenu *menu)
|
|
{
|
|
QPushButton *btn = getButton(button);
|
|
|
|
if (btn)
|
|
btn->setMenu(menu);
|
|
}
|
|
|
|
|
|
QPushButton *LtsDialogButtonBox::getButton(DialogButton button) const
|
|
{
|
|
switch (button)
|
|
{
|
|
case DialogButton::ReadOnly:
|
|
return m_ui->pbReadOnly;
|
|
case DialogButton::Ok:
|
|
return m_ui->pbOk;
|
|
case DialogButton::Apply:
|
|
return m_ui->pbApply;
|
|
case DialogButton::Close:
|
|
return m_ui->pbClose;
|
|
case DialogButton::Yes:
|
|
return m_ui->pbYes;
|
|
case DialogButton::No:
|
|
return m_ui->pbNo;
|
|
case DialogButton::Remove:
|
|
return m_ui->pbRemove;
|
|
case DialogButton::Hide:
|
|
return m_ui->pbHide;
|
|
case DialogButton::Add:
|
|
return m_ui->pbAdd;
|
|
case DialogButton::Help:
|
|
return m_ui->pbHelp;
|
|
case DialogButton::Edit:
|
|
return m_ui->pbEdit;
|
|
case DialogButton::Save:
|
|
return m_ui->pbSave;
|
|
case DialogButton::Load:
|
|
return m_ui->pbLoad;
|
|
case DialogButton::Show:
|
|
return m_ui->pbShow;
|
|
case DialogButton::Import:
|
|
return m_ui->pbImport;
|
|
case DialogButton::Export:
|
|
return m_ui->pbExport;
|
|
case DialogButton::Library:
|
|
return m_ui->pbLibrary;
|
|
case DialogButton::CenterMap:
|
|
return m_ui->pbCenterMap;
|
|
case DialogButton::ZoomMapTo:
|
|
return m_ui->pbZoomMapTo;
|
|
case DialogButton::Print:
|
|
return m_ui->pbPrint;
|
|
#ifdef LTS_DEBUG
|
|
case DialogButton::_debug_:
|
|
return m_ui->_pbChanges;
|
|
#endif
|
|
}
|
|
Q_ASSERT(false);
|
|
return nullptr; // sec
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::slotRemoveClicked()
|
|
{
|
|
if (LtsMessageDialog::showMessage(this,
|
|
tr("Are you sure you want to delete the selected entry(ies)?"),
|
|
tr("Remove selected entry(ies)"),
|
|
Behaviour::Modal,
|
|
Button::Yes | Button::No)
|
|
== Button::Yes)
|
|
emit signalRemoveClicked();
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setButtonsVisible(QPushButton *pb)
|
|
{
|
|
if (!pb || (pb == m_ui->pbPrint && m_isTablet))
|
|
return;
|
|
m_ui->line->setVisible(true);
|
|
pb->setVisible(true);
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setButtonVisible(DialogButton button, bool visible)
|
|
{
|
|
QPushButton *pb = getButton(button);
|
|
if (!pb)
|
|
return;
|
|
if (m_isTablet && pb == m_ui->pbPrint)
|
|
{
|
|
pb->setVisible(false);
|
|
return;
|
|
}
|
|
pb->setVisible(visible);
|
|
}
|
|
|
|
|
|
bool LtsDialogButtonBox::isButtonVisible(DialogButton button) const
|
|
{
|
|
const QPushButton *pb = getButton(button);
|
|
return (pb ? pb->isVisible() : false);
|
|
}
|
|
|
|
|
|
void LtsDialogButtonBox::setButtonEnabled(DialogButton button, bool enabled)
|
|
{
|
|
QPushButton *pb = getButton(button);
|
|
|
|
switch (button)
|
|
{
|
|
case DialogButton::Close:
|
|
case DialogButton::Ok:
|
|
case DialogButton::Apply:
|
|
//case DialogButton::Yes:
|
|
//case DialogButton::No:
|
|
{
|
|
#ifdef LTS_DEBUG
|
|
LtsMessageDialog::showMessage(this, QStringLiteral("Hier stimmt etwas nicht. Bitte MIKE bescheid geben WAS geklickt oder gemacht wurde als dieser Dialog auftauchte, damit ich es fixen kann. Danke."), QStringLiteral(">>> STOP <<<"));
|
|
#endif
|
|
break;
|
|
}
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (pb)
|
|
pb->setEnabled(enabled);
|
|
}
|
|
|
|
|
|
bool LtsDialogButtonBox::isButtonEnabled(DialogButton button) const
|
|
{
|
|
auto *that = const_cast<LtsDialogButtonBox *>(this); // ...
|
|
const QPushButton *pb = that->getButton(button);
|
|
return (pb ? pb->isEnabled() : false);
|
|
}
|
|
} // namespace LtsWidgets
|