Files
iDescriptor/src/responsiveqlabel.cpp
T
uncor3 8d4f4b11f9 improve UI styles
- Added album path management in PhotoModel for better photo loading.
- Updated responsive QLabel to handle scaling more effectively.
- Introduced ClickableIconWidget for better icon interaction in the UI.
- Added new color definitions for blue and accent blue.
- Enhanced the AppTabWidget styles to adapt to dark mode.
- Replaced QLineEdit with ZLineEdit for consistent styling.
- Improved the SSH terminal widget with better error handling and process management.
- Refactored ToolboxWidget methods for device management.
- Adjusted margins and styles in various widgets for improved layout.
2025-10-09 21:24:45 -07:00

66 lines
1.7 KiB
C++

#include "responsiveqlabel.h"
#include <QDebug>
#include <QPainter>
ResponsiveQLabel::ResponsiveQLabel(QWidget *parent) : QLabel(parent)
{
setAlignment(Qt::AlignCenter);
setScaledContents(false);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setMinimumSize(100, 100);
}
void ResponsiveQLabel::setPixmap(const QPixmap &pixmap)
{
m_originalPixmap = pixmap;
updateScaledPixmap();
}
void ResponsiveQLabel::resizeEvent(QResizeEvent *event)
{
QLabel::resizeEvent(event);
if (!m_originalPixmap.isNull()) {
updateScaledPixmap();
}
}
void ResponsiveQLabel::paintEvent(QPaintEvent *event)
{
if (m_scaledPixmap.isNull()) {
QLabel::paintEvent(event);
return;
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
// Calculate position to center the pixmap
int x = (width() - m_scaledPixmap.width()) / 2;
int y = (height() - m_scaledPixmap.height()) / 2;
painter.drawPixmap(x, y, m_scaledPixmap);
}
void ResponsiveQLabel::updateScaledPixmap()
{
if (m_originalPixmap.isNull()) {
return;
}
// Use the minimum width as the constraint for scaling
int targetWidth = qMax(minimumWidth(), width());
// Scale the pixmap while maintaining aspect ratio
m_scaledPixmap =
m_originalPixmap.scaled(targetWidth, QWIDGETSIZE_MAX,
Qt::KeepAspectRatio, Qt::SmoothTransformation);
// Resize the widget to match the scaled pixmap size
// This prevents the widget from taking up more space than the actual image
if (!m_scaledPixmap.isNull()) {
setFixedSize(m_scaledPixmap.size());
}
update();
}