File indexing completed on 2024-05-19 05:42:27
0001 // ct_lvtqtw_statusbar.cpp -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #include <ct_lvtqtw_modifierhelpers.h> 0021 #include <ct_lvtqtw_statusbar.h> 0022 #include <preferences.h> 0023 0024 namespace Codethink::lvtqtw { 0025 0026 CodeVisStatusBar::CodeVisStatusBar(): 0027 m_labelPan(new QPushButton(this)), 0028 m_labelZoom(new QPushButton(this)), 0029 m_labelParseCodebaseWindowStatus(new QPushButton(this)) 0030 { 0031 addWidget(m_labelPan); 0032 addWidget(m_labelZoom); 0033 m_labelPan->setFlat(true); 0034 m_labelZoom->setFlat(true); 0035 connect(m_labelPan, &QPushButton::clicked, this, &CodeVisStatusBar::mouseInteractionLabelClicked); 0036 connect(m_labelZoom, &QPushButton::clicked, this, &CodeVisStatusBar::mouseInteractionLabelClicked); 0037 0038 addWidget(new QLabel(" | ", this)); 0039 0040 addWidget(m_labelParseCodebaseWindowStatus); 0041 m_labelParseCodebaseWindowStatus->hide(); 0042 m_labelParseCodebaseWindowStatus->setFlat(true); 0043 m_labelParseCodebaseWindowStatus->setStyleSheet("font-weight: bold; color: #F19143;"); 0044 connect(m_labelParseCodebaseWindowStatus, &QPushButton::clicked, this, &CodeVisStatusBar::openParseCodebaseWindow); 0045 0046 connect(Preferences::self(), &Preferences::panModifierChanged, this, [this] { 0047 updatePanText(Preferences::panModifier()); 0048 }); 0049 connect(Preferences::self(), &Preferences::zoomModifierChanged, this, [this] { 0050 updateZoomText(Preferences::zoomModifier()); 0051 }); 0052 0053 updatePanText(Preferences::panModifier()); 0054 updateZoomText(Preferences::zoomModifier()); 0055 } 0056 0057 void CodeVisStatusBar::updatePanText(int newModifier) 0058 { 0059 auto modifier = static_cast<Qt::KeyboardModifier>(newModifier); 0060 if (modifier == Qt::KeyboardModifier::NoModifier) { 0061 m_labelPan->setText(tr("Pan Graph: Click")); 0062 } else { 0063 m_labelPan->setText(tr("Pan Graph: %1 + Click").arg(ModifierHelpers::modifierToText(modifier))); 0064 } 0065 } 0066 0067 void CodeVisStatusBar::updateZoomText(int newModifier) 0068 { 0069 auto modifier = static_cast<Qt::KeyboardModifier>(newModifier); 0070 if (modifier == Qt::KeyboardModifier::NoModifier) { 0071 m_labelZoom->setText(tr("Zoom: Wheel")); 0072 } else { 0073 m_labelZoom->setText(tr("Zoom: %1 + Wheel").arg(ModifierHelpers::modifierToText(modifier))); 0074 } 0075 } 0076 0077 void CodeVisStatusBar::reset() 0078 { 0079 m_labelParseCodebaseWindowStatus->setText(QString{""}); 0080 m_labelParseCodebaseWindowStatus->hide(); 0081 } 0082 0083 void CodeVisStatusBar::setParseCodebaseWindow(ParseCodebaseDialog& dialog) 0084 { 0085 if (m_parseCodebaseDialog) { 0086 disconnect(m_parseCodebaseDialog, 0087 &ParseCodebaseDialog::parseStarted, 0088 this, 0089 &CodeVisStatusBar::handleParseStart); 0090 disconnect(m_parseCodebaseDialog, &ParseCodebaseDialog::parseStep, this, &CodeVisStatusBar::handleParseStep); 0091 disconnect(m_parseCodebaseDialog, 0092 &ParseCodebaseDialog::parseFinished, 0093 this, 0094 &CodeVisStatusBar::handleParseFinished); 0095 } 0096 m_parseCodebaseDialog = &dialog; 0097 connect(m_parseCodebaseDialog, &ParseCodebaseDialog::parseStarted, this, &CodeVisStatusBar::handleParseStart); 0098 connect(m_parseCodebaseDialog, &ParseCodebaseDialog::parseStep, this, &CodeVisStatusBar::handleParseStep); 0099 connect(m_parseCodebaseDialog, &ParseCodebaseDialog::parseFinished, this, &CodeVisStatusBar::handleParseFinished); 0100 } 0101 0102 void CodeVisStatusBar::handleParseStart(ParseCodebaseDialog::State state) 0103 { 0104 m_labelParseCodebaseWindowStatus->show(); 0105 } 0106 0107 void CodeVisStatusBar::handleParseStep(ParseCodebaseDialog::State state, int currentProgress, int maxProgress) 0108 { 0109 if (state == ParseCodebaseDialog::State::RunAllLogical) { 0110 auto message = std::string("Running logical parse ["); 0111 message += std::to_string(currentProgress) + "/" + std::to_string(maxProgress); 0112 message += "]. Some diagrams may be incomplete."; 0113 m_labelParseCodebaseWindowStatus->setText(QString::fromStdString(message)); 0114 } 0115 0116 if (state == ParseCodebaseDialog::State::RunAllPhysical || state == ParseCodebaseDialog::State::RunPhysicalOnly) { 0117 auto message = std::string("Running physical parse ["); 0118 message += std::to_string(currentProgress) + "/" + std::to_string(maxProgress); 0119 message += "]."; 0120 m_labelParseCodebaseWindowStatus->setText(QString::fromStdString(message)); 0121 } 0122 } 0123 0124 void CodeVisStatusBar::handleParseFinished() 0125 { 0126 m_labelParseCodebaseWindowStatus->setText(QString{"View last parse run"}); 0127 } 0128 0129 void CodeVisStatusBar::openParseCodebaseWindow() const 0130 { 0131 if (!m_parseCodebaseDialog) { 0132 return; 0133 } 0134 m_parseCodebaseDialog->show(); 0135 } 0136 0137 } // namespace Codethink::lvtqtw