File size: 3,995 Bytes
a5ffdcd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | /*******************************************************************************
*
This file is part of the LibreCAD project, a 2D CAD program
Copyright (C) 2024 LibreCAD.org
Copyright (C) 2024 sand1024
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
******************************************************************************/
#include "lc_optionswidgetsholder.h"
#include "lc_shortcuts_manager.h"
#include "rs_settings.h"
#include "ui_lc_optionswidgetsholder.h"
LC_OptionsWidgetsHolder::LC_OptionsWidgetsHolder(QWidget *parent)
: QWidget(parent)
, ui(new Ui::LC_OptionsWidgetsHolder){
ui->setupUi(this);
ui->snapOptionsHolder->setLocatedOnLeft(true);
ui->vCurrentActionLine->setVisible(false);
ui->lCurrentAction->setToolTip(tr("Current Action:")+ " " + tr("Default"));
}
LC_OptionsWidgetsHolder::~LC_OptionsWidgetsHolder(){
delete ui;
}
LC_SnapOptionsWidgetsHolder *LC_OptionsWidgetsHolder::getSnapOptionsHolder() {
return ui->snapOptionsHolder;
}
#define DEBUG_WIDGETS_COUNT_
void LC_OptionsWidgetsHolder::addOptionsWidget(QWidget *optionsWidget) {
if (optionsWidget != nullptr) {
if (m_hasActionIcon) {
ui->vCurrentActionLine->setVisible(true);
}
ui->wOptionsWidgetsContainer->layout()->addWidget(optionsWidget);
#ifdef DEBUG_WIDGETS_COUNT
const QObjectList &list = ui->wOptionsWidgetsContainer->children();
if (!list.isEmpty()) {
int size = list.size();
LC_ERR << "OPTION WIDGETS: " << size;
}
#endif
}
}
void LC_OptionsWidgetsHolder::removeOptionsWidget(QWidget *optionsWidget) {
ui->vCurrentActionLine->setVisible(false);
if (optionsWidget != nullptr) {
#ifdef DEBUG_WIDGETS_COUNT
const QObjectList &list = ui->wOptionsWidgetsContainer->children();
LC_ERR << "OPTION WIDGETS BEFORE: " << list.size();
#endif
ui->wOptionsWidgetsContainer->layout()->removeWidget(optionsWidget);
optionsWidget->deleteLater();
#ifdef DEBUG_WIDGETS_COUNT
const QObjectList &listAfter = ui->wOptionsWidgetsContainer->children();
LC_ERR << "OPTION WIDGETS AFTER: " << listAfter.size();
#endif
}
}
void LC_OptionsWidgetsHolder::clearActionIcon() {
auto i = QIcon();
m_hasActionIcon = false;
doSetIcon(i,"");
}
void LC_OptionsWidgetsHolder::setCurrentQAction(QAction *a) {
QIcon icon;
QString text="";
bool showIcon = a != nullptr && LC_GET_ONE_BOOL("Appearance", "ShowActionIconInOptions", true);
if (showIcon) {
// check for actions those icons should not be shown
auto property = a->property("_SetAsCurrentActionInView");
if (property.isValid()) {
showIcon = property.toBool();
}
}
if (showIcon){
icon = a->icon();
text = LC_ShortcutsManager::getPlainActionToolTip(a);
m_hasActionIcon = true;
ui->vCurrentActionLine->setVisible(!icon.isNull());
}
else{
icon = QIcon();
m_hasActionIcon = false;
ui->vCurrentActionLine->setVisible(false);
text =tr("Default");
}
doSetIcon(icon, text);
}
void LC_OptionsWidgetsHolder::doSetIcon(const QIcon &icon, const QString& text) {
ui->lCurrentAction->setPixmap(icon.pixmap(iconSize));
ui->lCurrentAction->setToolTip(tr("Current Action:")+ " " + text);
}
|