Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
matrixcombopopup.h
1/*
2 * Copyright (C) 2025 Andrés Martínez Mera - andresmmera@protonmail.com
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef MATRIXCOMBOBOX_H
19#define MATRIXCOMBOBOX_H
20
21#include <QComboBox>
22#include <QFrame>
23#include <QGridLayout>
24#include <QPaintEvent>
25#include <QPushButton>
26#include <QStringList>
27#include <QVBoxLayout>
28#include <QApplication>
29#include <QEvent>
30#include <QFrame>
31#include <QGraphicsDropShadowEffect>
32#include <QHoverEvent>
33#include <QScreen>
34#include <QScrollArea>
35#include <QStyle>
36#include <QStyleOptionComboBox>
37#include <cmath> // for sqrt
38
42class MatrixComboPopup : public QFrame {
43 Q_OBJECT
44
45public:
52 MatrixComboPopup(const QStringList& sParams, const QStringList& otherParams,
53 QComboBox* parent = nullptr);
54
59 void showBelow(QWidget* widget);
60
61private slots:
65 void selectItem();
66
67private:
68 QComboBox* parentCombo;
69};
70
74class MatrixComboBox : public QComboBox {
75 Q_OBJECT
76
77public:
82 explicit MatrixComboBox(QWidget* parent = nullptr);
83
89 void setParameters(const QStringList& sParams,
90 const QStringList& otherParams);
91
92protected:
96 void showPopup() override;
97
101 void hidePopup() override;
102
107 void paintEvent(QPaintEvent* event) override;
108
109private:
110 QStringList sParams;
111 QStringList otherParams;
112 bool popupVisible;
113 MatrixComboPopup* popup;
114};
115
119class HoverButton : public QPushButton {
120public:
126 HoverButton(const QString& text, QWidget* parent = nullptr)
127 : QPushButton(text, parent) {
128 setFlat(true);
129 setMouseTracking(true);
130
131 // Create initial style
132 setStyleSheet("QPushButton {"
133 " padding: 5px;"
134 " border: none;"
135 " background-color: transparent;"
136 " text-align: left;"
137 "}"
138 "QPushButton:hover {"
139 " background-color: rgba(0, 0, 0, 10%);"
140 " border-radius: 3px;"
141 "}");
142
143 // Create shadow effect (hidden by default)
144 shadowEffect = new QGraphicsDropShadowEffect(this);
145 shadowEffect->setBlurRadius(10);
146 shadowEffect->setColor(QColor(0, 0, 0, 80));
147 shadowEffect->setOffset(0, 0);
148 shadowEffect->setEnabled(false);
149 setGraphicsEffect(shadowEffect);
150 }
151
152protected:
158 bool event(QEvent* event) override {
159 if (event->type() == QEvent::HoverEnter) {
160 shadowEffect->setEnabled(true);
161 } else if (event->type() == QEvent::HoverLeave) {
162 shadowEffect->setEnabled(false);
163 }
164 return QPushButton::event(event);
165 }
166
167private:
168 QGraphicsDropShadowEffect* shadowEffect;
169};
170
171
172
173#endif // MATRIXCOMBOBOX_H
Custom button with hover effect and shadow.
Definition matrixcombopopup.cpp:31
HoverButton(const QString &text, QWidget *parent=nullptr)
Constructor.
Definition matrixcombopopup.h:126
bool event(QEvent *event) override
Handles hover events to show/hide shadow.
Definition matrixcombopopup.h:158
ComboBox with custom matrix-style popup for parameter selection.
Definition matrixcombopopup.h:44
void showPopup() override
Shows custom matrix popup instead of standard dropdown.
MatrixComboBox(QWidget *parent=nullptr)
Constructor.
void hidePopup() override
Hides the custom popup.
void setParameters(const QStringList &sParams, const QStringList &otherParams)
Sets parameters to display in popup.
void paintEvent(QPaintEvent *event) override
Custom paint to show popup state.
Custom popup displaying S-parameters in matrix layout with other parameters below.
Definition matrixcombopopup.h:29
void showBelow(QWidget *widget)
Shows popup below specified widget.
MatrixComboPopup(const QStringList &sParams, const QStringList &otherParams, QComboBox *parent=nullptr)
Constructor.