36 #include <QMouseEvent> 78 QRect rect = contentsRect();
95 height = rect.height();
98 double layout_ar = width / height;
100 if (layout_ar > image_ar)
103 width = height * image_ar;
108 height = width / image_ar;
110 rect.setWidth(
int(width + 0.5));
111 rect.setHeight(
int(height + 0.5));
114 int border = lineWidth();
115 resize(rect.width() + 2 * border, rect.height() + 2 * border);
125 int border = lineWidth();
126 QSize new_size = size;
127 new_size += QSize(2 * border, 2 * border);
128 setMinimumSize(new_size);
134 int border = lineWidth();
135 QSize new_size = size;
136 new_size += QSize(2 * border, 2 * border);
137 setMaximumSize(new_size);
158 QPainter painter(
this);
167 painter.drawImage(contentsRect(),
qimage_);
169 if (contentsRect().width() ==
qimage_.width()) {
170 painter.drawImage(contentsRect(),
qimage_);
172 QImage image =
qimage_.scaled(contentsRect().width(), contentsRect().height(),
173 Qt::KeepAspectRatio, Qt::SmoothTransformation);
174 painter.drawImage(contentsRect(), image);
179 QLinearGradient gradient(0, 0, frameRect().width(), frameRect().height());
180 gradient.setColorAt(0, Qt::white);
181 gradient.setColorAt(1, Qt::black);
182 painter.setBrush(gradient);
183 painter.drawRect(0, 0, frameRect().width() + 1, frameRect().height() + 1);
199 if(mouseEvent->button() == Qt::LeftButton)
201 emit
mouseLeft(mouseEvent->x(), mouseEvent->y());
203 QFrame::mousePressEvent(mouseEvent);
void setOuterLayout(QHBoxLayout *outer_layout)
RatioLayoutedFrame(QWidget *parent, Qt::WindowFlags flags=0)
QImage getImageCopy() const
void mouseLeft(int x, int y)
void update(const std::string &key, const XmlRpc::XmlRpcValue &v)
const QImage & getImage() const
void setInnerFrameMinimumSize(const QSize &size)
static int greatestCommonDivisor(int a, int b)
void mousePressEvent(QMouseEvent *mouseEvent)
void setInnerFrameMaximumSize(const QSize &size)
virtual ~RatioLayoutedFrame()
void setInnerFrameFixedSize(const QSize &size)
void setAspectRatio(unsigned short width, unsigned short height)
void setImage(const QImage &image)
void paintEvent(QPaintEvent *event)
QHBoxLayout * outer_layout_
void resizeToFitAspectRatio()
void onSmoothImageChanged(bool checked)