File indexing completed on 2024-12-22 04:15:12

0001 /*
0002  *  SPDX-FileCopyrightText: 2023 Srirupa Datta <srirupa.sps@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "wdg_side.h"
0008 #include "ui_wdgside.h"
0009 #include <kis_icon.h>
0010 #include <QToolButton>
0011 #include <QPalette>
0012 
0013 #include <QLabel>
0014 #include <QVBoxLayout>
0015 #include <QApplication>
0016 
0017 WdgSide::WdgSide(KoResourceBundleSP bundle, QWidget *parent) :
0018     QWidget(parent),
0019     m_ui(new Ui::WdgSide)
0020     , m_bundle(bundle)
0021 {
0022     m_ui->setupUi(this);
0023 
0024     QCoreApplication* coreApp = QCoreApplication::instance();
0025     QApplication* app = qobject_cast<QApplication*>(coreApp);
0026     QPalette appPalette = app->palette();
0027     QColor brightColor = appPalette.color(QPalette::Highlight);
0028     QString styleSheet = QString("QToolButton { background-color: %1; color: %2; }")
0029                         .arg(brightColor.name())
0030                         .arg(brightColor.lightnessF() < 0.5 ? "#FFFFFF" : "#000000");
0031 
0032     m_ui->btnChooseRes->setIcon(KisIconUtils::loadIcon("document-edit"));
0033     m_ui->btnChooseRes->setIconSize(QSize(28, 28));
0034     m_ui->btnChooseRes->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0035 
0036     m_ui->btnChooseTags->setIcon(KisIconUtils::loadIcon("bookmarks"));
0037     m_ui->btnChooseTags->setIconSize(QSize(28, 28));
0038     m_ui->btnChooseTags->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0039 
0040     m_ui->btnBundleInfo->setIcon(KisIconUtils::loadIcon("configure"));
0041     m_ui->btnBundleInfo->setIconSize(QSize(28, 28));
0042     m_ui->btnBundleInfo->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0043 
0044     m_ui->btnSaveLocation->setIcon(KisIconUtils::loadIcon("folder"));
0045     m_ui->btnSaveLocation->setIconSize(QSize(28, 28));
0046     m_ui->btnSaveLocation->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
0047 
0048     m_ui->btnChooseRes->setStyleSheet(styleSheet);
0049 }
0050 
0051 void WdgSide::focusLabel(int id)
0052 {
0053     QCoreApplication* coreApp = QCoreApplication::instance();
0054     QApplication* app = qobject_cast<QApplication*>(coreApp);
0055     QPalette appPalette = app->palette();
0056     QColor brightColor = appPalette.color(QPalette::Midlight);
0057     QString styleSheetHighlight = QString("QToolButton { background-color: %1; color: %2; }")
0058                         .arg(brightColor.name())
0059                         .arg(brightColor.lightnessF() < 0.5 ? "#FFFFFF" : "#000000");
0060 
0061     QColor normalColor = appPalette.color(QPalette::Base);
0062     QString styleSheetNormal = QString("QToolButton { background-color: %1; color: %2; }")
0063                         .arg(normalColor.name())
0064                         .arg(normalColor.lightnessF() < 0.5 ? "#FFFFFF" : "#000000");
0065 
0066 
0067     switch(id) {
0068     case 1: {
0069                 m_ui->btnChooseRes->setStyleSheet(styleSheetHighlight);
0070                 m_ui->btnChooseTags->setStyleSheet(styleSheetNormal);
0071                 m_ui->btnBundleInfo->setStyleSheet(styleSheetNormal);
0072                 m_ui->btnSaveLocation->setStyleSheet(styleSheetNormal);
0073                 break;
0074             }
0075     case 2: {
0076                 m_ui->btnChooseRes->setStyleSheet(styleSheetNormal);
0077                 m_ui->btnChooseTags->setStyleSheet(styleSheetHighlight);
0078                 m_ui->btnBundleInfo->setStyleSheet(styleSheetNormal);
0079                 m_ui->btnSaveLocation->setStyleSheet(styleSheetNormal);
0080                 break;
0081             }
0082     case 3: {
0083                 m_ui->btnChooseRes->setStyleSheet(styleSheetNormal);
0084                 m_ui->btnChooseTags->setStyleSheet(styleSheetNormal);
0085                 m_ui->btnBundleInfo->setStyleSheet(styleSheetHighlight);
0086                 m_ui->btnSaveLocation->setStyleSheet(styleSheetNormal);
0087                 break;
0088             }
0089     case 4: {
0090                 m_ui->btnChooseRes->setStyleSheet(styleSheetNormal);
0091                 m_ui->btnChooseTags->setStyleSheet(styleSheetNormal);
0092                 m_ui->btnBundleInfo->setStyleSheet(styleSheetNormal);
0093                 m_ui->btnSaveLocation->setStyleSheet(styleSheetHighlight);
0094                 break;
0095             }
0096     }
0097 
0098 }
0099 
0100 WdgSide::~WdgSide()
0101 {
0102     delete m_ui;
0103 }