remove icon handling and simplify tab creation

This commit is contained in:
uncor3
2025-07-28 06:53:53 +00:00
parent 636a15355a
commit 5a04a9a03c
4 changed files with 46 additions and 226 deletions
+30 -96
View File
@@ -7,9 +7,9 @@
#include <QScrollArea>
#include <QSpinBox>
#include <QStyle>
#include <QTimer>
#include <QVBoxLayout>
#include <QWheelEvent>
DeviceTabWidget::DeviceTabWidget(QWidget *parent) : QTabWidget(parent)
{
setTabsClosable(false);
@@ -17,32 +17,26 @@ DeviceTabWidget::DeviceTabWidget(QWidget *parent) : QTabWidget(parent)
connect(this, &QTabWidget::tabCloseRequested, this,
&DeviceTabWidget::onCloseTab);
}
int DeviceTabWidget::addTabWithIcon(QWidget *widget, const QPixmap &icon,
const QString &text)
int DeviceTabWidget::addTabCustom(QWidget *widget, const QString &text)
{
int index = addTab(widget, text);
QWidget *tabWidget = createTabWidget(text, index);
// tabWidget->setMinimumHeight(220); // Set a minimum height for the tab
// widget tabWidget->setSizePolicy(QSizePolicy::Expanding,
// QSizePolicy::Expanding);
// tabWidget->setSizePolicy(QSizePolicy::Expanding,
// QSizePolicy::Preferred);
tabBar()->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
if (!icon.isNull()) {
QWidget *tabWidget = createTabWidget(icon, text, index);
// tabWidget->setMinimumHeight(220); // Set a minimum height for the tab
// widget tabWidget->setSizePolicy(QSizePolicy::Expanding,
// QSizePolicy::Expanding);
// tabWidget->setSizePolicy(QSizePolicy::Expanding,
// QSizePolicy::Preferred);
tabBar()->setTabButton(index, QTabBar::LeftSide, tabWidget);
tabBar()->setTabText(index, ""); // Clear the default text
}
tabBar()->setTabButton(index, QTabBar::LeftSide, tabWidget);
tabBar()->setTabText(index, ""); // Clear the default text
return index;
}
void DeviceTabWidget::wheelEvent(QWheelEvent *event)
{
// Ignore wheel events to prevent tab switching with scroll wheel
event->ignore();
}
void DeviceTabWidget::setTabIcon(int index, const QPixmap &icon)
{
if (index >= 0 && index < count()) {
@@ -57,49 +51,32 @@ void DeviceTabWidget::setTabIcon(int index, const QPixmap &icon)
}
}
}
QWidget *newTabWidget = createTabWidget(icon, text, index);
QWidget *newTabWidget = createTabWidget(text, index);
tabBar()->setTabButton(index, QTabBar::LeftSide, newTabWidget);
}
}
QWidget *DeviceTabWidget::createTabWidget(const QPixmap &icon,
const QString &text, int index)
QWidget *DeviceTabWidget::createTabWidget(const QString &text, int index)
{
QWidget *tabWidget = new QWidget();
tabWidget->setMinimumHeight(220); // Set a minimum height for the tab widget
// tabWidget->setMinimumHeight(220); // Set a minimum height for the tab
// widget
tabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
tabWidget->setStyleSheet("QWidget { "
" background-color:rgb(240, 0, 0); "
" border: 1px solid #ccc; "
" border-radius: 4px; "
"}");
QVBoxLayout *mainLayout = new QVBoxLayout(tabWidget);
mainLayout->setContentsMargins(5, 2, 5, 2);
mainLayout->setSpacing(2);
mainLayout->setSizeConstraint(QLayout::SetMinimumSize);
// Top section with icon and text
QWidget *topSection = new QWidget();
QHBoxLayout *topLayout = new QHBoxLayout(topSection);
topLayout->setContentsMargins(0, 0, 0, 0);
topLayout->setSpacing(5);
// Add icon
QLabel *iconLabel = new QLabel();
QPixmap scaledIcon =
icon.scaled(16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation);
iconLabel->setPixmap(scaledIcon);
topLayout->addWidget(iconLabel);
// Add text
QLabel *textLabel = new QLabel(text);
textLabel->setObjectName("textLabel");
topLayout->addWidget(textLabel);
mainLayout->addWidget(topSection);
// Create collapsible options section
QPushButton *toggleButton = new QPushButton("▶ Options");
toggleButton->setFlat(true);
@@ -109,29 +86,16 @@ QWidget *DeviceTabWidget::createTabWidget(const QPixmap &icon,
toggleButton->setMaximumHeight(25);
toggleButton->setCheckable(true);
toggleButton->setChecked(false);
// Create a scroll area for content
QScrollArea *contentArea = new QScrollArea();
contentArea->setStyleSheet(
"QScrollArea { border: 1px solid #ccc; background-color: #f8f8f8; }");
contentArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
contentArea->setMaximumHeight(0); // Start collapsed
contentArea->setMinimumHeight(0);
contentArea->setFrameShape(QFrame::NoFrame);
contentArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// Create a widget to hold the navigation buttons
QWidget *contentWidget = new QWidget();
contentWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
QVBoxLayout *optionsLayout = new QVBoxLayout(contentWidget);
optionsLayout->setContentsMargins(5, 5, 5, 5);
optionsLayout->setSpacing(3);
// Create navigation buttons
QPushButton *infoBtn = new QPushButton("Info");
QPushButton *appsBtn = new QPushButton("Apps");
QPushButton *galleryBtn = new QPushButton("Gallery");
QPushButton *filesBtn = new QPushButton("Files");
// Set button properties
QList<QPushButton *> buttons = {infoBtn, appsBtn, galleryBtn, filesBtn};
for (QPushButton *btn : buttons) {
@@ -155,10 +119,8 @@ QWidget *DeviceTabWidget::createTabWidget(const QPixmap &icon,
" background-color: #106ebe; "
"}");
}
// Set info as default active
infoBtn->setChecked(true);
// Connect button group behavior and emit signals
for (QPushButton *btn : buttons) {
connect(btn, &QPushButton::clicked, [this, buttons, btn, index]() {
@@ -171,65 +133,37 @@ QWidget *DeviceTabWidget::createTabWidget(const QPixmap &icon,
emit navigationButtonClicked(index, btn->text());
});
}
// Add buttons to layout
optionsLayout->addWidget(infoBtn);
optionsLayout->addWidget(appsBtn);
optionsLayout->addWidget(galleryBtn);
optionsLayout->addWidget(filesBtn);
// Set the content widget in the scroll area
contentArea->setWidget(contentWidget);
contentArea->setWidgetResizable(true);
// Calculate content height
contentWidget->adjustSize();
int contentHeight = contentWidget->height() + 10; // Add some padding
// Create animation for expanding/collapsing
QPropertyAnimation *animation =
new QPropertyAnimation(contentArea, "maximumHeight");
animation->setDuration(300); // 300ms animation
animation->setStartValue(0);
animation->setEndValue(contentHeight);
// Add widgets to main layout
mainLayout->addWidget(toggleButton);
mainLayout->addWidget(contentArea);
// Connect toggle button to animation
mainLayout->addWidget(contentWidget);
contentWidget->setVisible(false); // Initially hidden
// Connect toggle button to expand/collapse
int prevHeight = tabBar()->sizeHint().height();
connect(toggleButton, &QPushButton::clicked,
[toggleButton, animation, contentArea, contentHeight]() {
// Toggle content visibility with animation
[this, toggleButton, contentWidget, prevHeight]() {
// Toggle content visibility
bool isExpanded = toggleButton->isChecked();
contentWidget->setVisible(isExpanded);
if (isExpanded) {
// Expanding
toggleButton->setText("▼ Options");
animation->setDirection(QAbstractAnimation::Forward);
animation->start();
tabBar()->resize(tabBar()->sizeHint().width(),
contentWidget->sizeHint().height() +
tabBar()->sizeHint().height());
tabBar()->adjustSize();
} else {
// Collapsing
toggleButton->setText("▶ Options");
animation->setDirection(QAbstractAnimation::Backward);
animation->start();
tabBar()->setFixedHeight(prevHeight);
}
// QTimer::singleShot(0, tabBar(), &QWidget::adjustSize);
});
connect(animation, &QPropertyAnimation::finished, [this]() {
// Find the tallest tab button widget
int maxHeight = 0;
for (int i = 0; i < tabBar()->count(); ++i) {
QWidget *tabBtn = tabBar()->tabButton(i, QTabBar::LeftSide);
if (tabBtn) {
maxHeight = std::max(maxHeight, tabBtn->sizeHint().height());
}
}
// Set tabBar minimum height to fit the tallest tab button
tabBar()->setMinimumHeight(maxHeight);
});
return tabWidget;
}
void DeviceTabWidget::onCloseTab(int index) { removeTab(index); }
void DeviceTabWidget::onCloseTab(int index) { removeTab(index); }
+2 -4
View File
@@ -12,8 +12,7 @@ class DeviceTabWidget : public QTabWidget
public:
explicit DeviceTabWidget(QWidget *parent = nullptr);
int addTabWithIcon(QWidget *widget, const QPixmap &icon,
const QString &text);
int addTabCustom(QWidget *widget, const QString &text);
void setTabIcon(int index, const QPixmap &icon);
signals:
@@ -23,8 +22,7 @@ private slots:
void onCloseTab(int index);
private:
QWidget *createTabWidget(const QPixmap &icon, const QString &text,
int index);
QWidget *createTabWidget(const QString &text, int index);
protected:
void wheelEvent(QWheelEvent *event) override;
+14 -125
View File
@@ -42,13 +42,10 @@ void handleCallback(const idevice_event_t *event, void *userData)
switch (event->event) {
case IDEVICE_DEVICE_ADD: {
// this should never happen iDescriptor does not support network devices
// yet
// for some reason even though we are only listening for USB devices, we
// still get network devices on macOS
/* this should never happen iDescriptor does not support network devices
but for some reason even though we are only listening for USB devices,
we still get network devices on macOS*/
if (event->conn_type == CONNECTION_NETWORK) {
warn("Network devices are not supported but a network device was "
"received in event listener. Please report this issue.");
return;
}
qDebug() << "Device added: " << QString::fromUtf8(event->udid);
@@ -138,38 +135,16 @@ MainWindow::MainWindow(QWidget *parent)
ui->mainTabWidget->widget(3)->layout()->addWidget(
new JailbrokenWidget(this));
// // QGraphicsScene *scene = new QGraphicsScene(this);
// // QGraphicsSvgItem *svgItem = new
// QGraphicsSvgItem("://icons/ArrowMoveDownRight.svg");
// // scene->addItem(svgItem);
// // // Fit to view
// // svgItem->setFlags(QGraphicsItem::ItemClipsToShape);
// // svgItem->setCacheMode(QGraphicsItem::NoCache);
// // svgItem->setZValue(0);
// // svgItem->setScale(2.0); // or calculate scale to fit the view
// // ui->graphicsView->setScene(scene);
// // ui->graphicsView->setRenderHint(QPainter::Antialiasing);
// // ui->graphicsView->fitInView(svgItem, Qt::KeepAspectRatio);
// #include "./imobiledevice.cpp"
customTabWidget->tabBar()->setMinimumWidth(150);
customTabWidget->tabBar()->setMinimumWidth(75);
customTabWidget->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Preferred);
customTabWidget->setStyleSheet("QTabWidget::pane {"
" border: 1px solid #ccc;"
" background-color: rgb(240, 240, 240);"
// " border: 1px solid #ccc;"
"}"
"QTabBar::tab {"
" background-color: rgb(220, 220, 220);"
" padding: 5px;"
"}");
customTabWidget->tabBar()->setMinimumHeight(100);
customTabWidget->tabBar()->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Preferred);
// customTabWidget->tabBar()->setMinimumHeight(100);
irecv_error_t res_recovery =
irecv_device_event_subscribe(&context, handleCallbackRecovery, nullptr);
@@ -191,15 +166,14 @@ MainWindow::MainWindow(QWidget *parent)
DeviceMenuWidget *deviceWidget = new DeviceMenuWidget(device, this);
m_device_menu_widgets[device->udid] = deviceWidget;
// Get device icon and product type for tab
QPixmap deviceIcon = getDeviceIcon(device->deviceInfo.productType);
QString tabTitle =
QString::fromStdString(device->deviceInfo.productType);
// Add tab with custom icon
DeviceTabWidget *customTabWidget =
qobject_cast<DeviceTabWidget *>(ui->tabWidget);
int mostRecentDevice = customTabWidget->addTabWithIcon(
deviceWidget, deviceIcon, tabTitle);
int mostRecentDevice =
customTabWidget->addTabCustom(deviceWidget, tabTitle);
customTabWidget->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Preferred);
@@ -258,7 +232,7 @@ MainWindow::MainWindow(QWidget *parent)
// int mostRecentDevice = customTabWidget->addTabWithIcon(
// placeholderWidget, placeholderIcon, tabTitle);
int mostRecentDevice = ui->tabWidget->addTab(
placeholderWidget, getDeviceIcon(udid.toStdString()),
placeholderWidget, QIcon(),
QString::fromStdString(udid.toStdString()));
// customTabWidget->setSizePolicy(QSizePolicy::Expanding,
// QSizePolicy::Preferred);
@@ -297,11 +271,9 @@ MainWindow::MainWindow(QWidget *parent)
QString tabTitle =
QString::fromStdString(device->deviceInfo.productType);
QPixmap placeholderIcon(16, 16);
placeholderIcon.fill(Qt::red);
int mostRecentDevice = customTabWidget->addTabWithIcon(
deviceWidget, placeholderIcon, tabTitle);
int mostRecentDevice =
customTabWidget->addTabCustom(deviceWidget, tabTitle);
// int mostRecentDevice = ui->tabWidget->addTab(
// placeholderWidget, getDeviceIcon(udid.toStdString()),
// QString::fromStdString(udid.toStdString()));
@@ -335,29 +307,6 @@ MainWindow::MainWindow(QWidget *parent)
});
}
QPixmap MainWindow::getDeviceIcon(const std::string &productType)
{
// Create a simple colored icon based on device type
QPixmap icon(16, 16);
icon.fill(Qt::transparent);
QPainter painter(&icon);
painter.setRenderHint(QPainter::Antialiasing);
if (productType.find("iPhone") != std::string::npos) {
painter.setBrush(QColor(0, 122, 255)); // iOS blue
painter.drawEllipse(2, 2, 12, 12);
} else if (productType.find("iPad") != std::string::npos) {
painter.setBrush(QColor(255, 149, 0)); // Orange
painter.drawRect(2, 2, 12, 12);
} else {
painter.setBrush(QColor(128, 128, 128)); // Gray for unknown
painter.drawEllipse(2, 2, 12, 12);
}
return icon;
}
void MainWindow::updateNoDevicesConnected()
{
qDebug() << "Is there no devices connected? "
@@ -408,7 +357,6 @@ void MainWindow::onRecoveryDeviceAdded(QObject *recoveryDeviceInfoObj)
m_device_menu_widgets[added_ecid] = recoveryDeviceInfoWidget;
// Get device icon and product type for tab
QPixmap deviceIcon = getDeviceIcon(device->product.toStdString());
// QString tabTitle =
// QString::fromStdString(device->product.toStdString());
QString tabTitle = QString::fromStdString("recovery mode device");
@@ -416,8 +364,8 @@ void MainWindow::onRecoveryDeviceAdded(QObject *recoveryDeviceInfoObj)
// Add tab with custom icon
DeviceTabWidget *customTabWidget =
qobject_cast<DeviceTabWidget *>(ui->tabWidget);
int mostRecentDevice = customTabWidget->addTabWithIcon(
recoveryDeviceInfoWidget, deviceIcon, tabTitle);
int mostRecentDevice =
customTabWidget->addTabCustom(recoveryDeviceInfoWidget, tabTitle);
customTabWidget->setSizePolicy(QSizePolicy::Expanding,
QSizePolicy::Preferred);
@@ -441,24 +389,6 @@ void MainWindow::onRecoveryDeviceAdded(QObject *recoveryDeviceInfoObj)
this, "Error",
"An error occurred while processing device information");
}
// RecoveryDeviceInfoWidget *recoveryDeviceInfoWidget = new
// RecoveryDeviceInfoWidget(recoveryDeviceInfoObj); QPixmap recoveryIcon(16,
// 16); recoveryIcon.fill(Qt::transparent); QPainter painter(&recoveryIcon);
// painter.setRenderHint(QPainter::Antialiasing);
// painter.setBrush(QColor(255, 59, 48)); // Red for recovery mode
// painter.drawRoundedRect(2, 2, 12, 12, 2, 2);
// DeviceTabWidget *customTabWidget = qobject_cast<DeviceTabWidget
// *>(ui->tabWidget);
// int mostRecentDevice =
// customTabWidget->addTabWithIcon(recoveryDeviceInfoWidget, recoveryIcon,
// "Recovery Mode");
// ui->tabWidget->setCurrentIndex(mostRecentDevice);
// recoveryDeviceInfoObj->deleteLater(); // Clean up
}
void MainWindow::onRecoveryDeviceRemoved(QObject *deviceInfoObj)
@@ -565,45 +495,4 @@ void MainWindow::onDeviceInitFailed(QString udid, lockdownd_error_t err)
errorDialog.setIcon(QMessageBox::Warning);
errorDialog.setStandardButtons(QMessageBox::Ok);
errorDialog.exec();
}
// void MainWindow::on_pushButton_clicked()
// {
// QMainWindow *newWin = new QMainWindow();
// newWin->setWindowTitle("New Window");
// newWin->resize(600, 400);
// newWin->show(); // show non-modally
// }
// // // mainwindow.cpp
// // void MainWindow::openNewWindow() {
// // QMainWindow* newWin = new QMainWindow();
// // newWin->setWindowTitle("New Window");
// // newWin->resize(600, 400);
// // newWin->show(); // show non-modally
// // }
// void MainWindow::on_pushButton_2_clicked()
// {
// DetailWindow *dWindow = new DetailWindow("iDeviceDetails", 42);
// dWindow->show();
// }
// void MainWindow::on_pushButton_3_clicked()
// {
// QMessageBox::StandardButton reply;
// reply = QMessageBox::question(this, "Confirm Action", "Do you want to
// continue?",
// QMessageBox::Yes | QMessageBox::No);
// if (reply == QMessageBox::Yes)
// {
// // user clicked Yes
// DetailWindow *dWindow = new DetailWindow("yess", 42);
// dWindow->show();
// }
// else
// {
// // user clicked No
// }
// }
}
-1
View File
@@ -36,6 +36,5 @@ private:
std::map<std::string, QWidget *>
m_device_menu_widgets; // Map to store devices by UDID
Ui::MainWindow *ui;
QPixmap getDeviceIcon(const std::string &productType);
};
#endif // MAINWINDOW_H