diff --git a/qtox.pro b/qtox.pro
index 748dfb753..28ae6d613 100644
--- a/qtox.pro
+++ b/qtox.pro
@@ -494,7 +494,8 @@ SOURCES += \
src/widget/friendlistlayout.cpp \
src/widget/genericchatitemlayout.cpp \
src/widget/categorywidget.cpp \
- src/widget/tool/movablewidget.cpp
+ src/widget/tool/movablewidget.cpp \
+ src/widget/tool/aspectratiowidget.cpp
HEADERS += \
src/audio/audio.h \
@@ -538,4 +539,5 @@ HEADERS += \
src/widget/friendlistlayout.h \
src/widget/genericchatitemlayout.h \
src/widget/categorywidget.h \
- src/widget/tool/movablewidget.h
+ src/widget/tool/movablewidget.h \
+ src/widget/tool/aspectratiowidget.h
diff --git a/src/mainwindow.ui b/src/mainwindow.ui
index 9e73284de..da3e67da6 100644
--- a/src/mainwindow.ui
+++ b/src/mainwindow.ui
@@ -1085,7 +1085,7 @@ QSplitter:handle{
0
0
284
- 353
+ 341
@@ -1850,7 +1850,7 @@ QSplitter:handle{
0
0
775
- 22
+ 26
diff --git a/src/video/netcamview.cpp b/src/video/netcamview.cpp
index 5af313e29..55fb6ec5b 100644
--- a/src/video/netcamview.cpp
+++ b/src/video/netcamview.cpp
@@ -33,23 +33,39 @@ NetCamView::NetCamView(QWidget* parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
setWindowTitle(tr("Tox video"));
- setMinimumSize(320,240);
videoSurface = new VideoSurface(this);
+ videoSurface->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
+ videoSurface->setStyleSheet("background-color: blue;");
+ videoSurface->setMinimum(128);
- //mainLayout->addStretch();
- mainLayout->addWidget(videoSurface);
- //mainLayout->addStretch();
+ mainLayout->addStretch(1);
+ //QWidget* wid = new QWidget(this);
+ //wid->setMinimumSize(600, 600);
+ QVBoxLayout* horLayout = new QVBoxLayout();
+ horLayout->addStretch(1);
+ horLayout->addWidget(videoSurface);
+ horLayout->addStretch(1);
+ mainLayout->addLayout(horLayout);
- selfVideoSurface = new VideoSurface(this);
+ selfFrame = new MovableWidget(videoSurface);
+ selfFrame->show();
+
+ selfVideoSurface = new VideoSurface(selfFrame);
selfVideoSurface->setObjectName(QStringLiteral("CamVideoSurface"));
- selfVideoSurface->setMinimumSize(QSize(160, 120));
- selfVideoSurface->setSource(&CameraSource::getInstance());
+ selfVideoSurface->setMouseTracking(true);
- connect(&CameraSource::getInstance(), &CameraSource::deviceOpened, [this]()
+ QHBoxLayout* frameLayout = new QHBoxLayout(selfFrame);
+ frameLayout->addWidget(selfVideoSurface);
+ frameLayout->setMargin(0);
+
+ //mainLayout->addWidget(selfVideoSurface);
+ mainLayout->addStretch(1);
+
+ /*connect(&CameraSource::getInstance(), &CameraSource::deviceOpened, [this]()
{
connect(selfVideoSurface, &VideoSurface::drewNewFrame, this, &NetCamView::updateSize);
- });
+ });*/
QHBoxLayout* buttonLayout = new QHBoxLayout();
buttonLayout->addStretch();
@@ -57,24 +73,29 @@ NetCamView::NetCamView(QWidget* parent)
buttonLayout->addWidget(button);
connect(button, &QPushButton::clicked, this, &NetCamView::showMessageClicked);
- layout->addLayout(mainLayout);
+ layout->addLayout(mainLayout, 1);
layout->addLayout(buttonLayout);
setShowMessages(false);
+
+ setStyleSheet("NetCamView { background-color: #c1c1c1; }");
}
void NetCamView::show(VideoSource *source, const QString &title)
{
setSource(source);
+ //selfVideoSurface->setSource(&CameraSource::getInstance());
setTitle(title);
QWidget::show();
- updateSize();
+ //updateSize();
}
void NetCamView::hide()
{
+ qDebug() << "jd";
setSource(nullptr);
+ selfVideoSurface->setSource(nullptr);
if (selfFrame)
selfFrame->deleteLater();
@@ -109,6 +130,14 @@ void NetCamView::setShowMessages(bool show, bool notify)
button->setIcon(QIcon());
}
}
+#include
+#include "src/widget/style.h"
+void NetCamView::paintEvent(QPaintEvent*)
+{
+ QPainter painter(this);
+ painter.setBrush(Style::getColor(Style::ThemeDark));
+ painter.drawRect(rect());
+}
void NetCamView::resizeEvent(QResizeEvent* event)
{
@@ -118,53 +147,23 @@ void NetCamView::resizeEvent(QResizeEvent* event)
void NetCamView::updateSize()
{
- // Check there is room for a second video.
- // If so, then we will show the user video there too.
- //qDebug() << selfVideoSurface->getRect().size() == ;
- bool hasRoom = selfVideoSurface->getRect().width() != 0 && videoSurface->getRect().width() * 2 < layout()->contentsRect().width() - layout()->margin();
+ qDebug() << videoSurface->size();
+ QSize usableSize = mainLayout->contentsRect().size();
+ int possibleWidth = usableSize.height() * videoSurface->getRatio();
- if (mainLayout->indexOf(selfVideoSurface) != -1)
- {
+ QSize initial = videoSurface->sizeHint();
- if (!hasRoom)
- {
- selfFrame = new MovableWidget(videoSurface);
- selfFrame->show();
+ if (!initial.isValid())
+ return;
- QHBoxLayout* camLayout = new QHBoxLayout(selfFrame);
- camLayout->addWidget(selfVideoSurface);
- camLayout->setMargin(0);
+ if (possibleWidth > usableSize.width())
+ videoSurface->setSizeHint(usableSize.width(), usableSize.width() / videoSurface->getRatio());
+ else
+ videoSurface->setSizeHint(usableSize.height() * videoSurface->getRatio(), usableSize.height());
- //selfFrame->setBoundary(videoSurface->getRect());
- updateFrameSize();
- }
- }
- else
- {
- if (hasRoom)
- {
- if (selfFrame)
- selfFrame->deleteLater();
+ videoSurface->updateGeometry();
- selfFrame = nullptr;
-
- mainLayout->addWidget(selfVideoSurface);
- }
- else if (selfFrame)
- {
- updateFrameSize();
- }
- }
-
- disconnect(selfVideoSurface, &VideoSurface::drewNewFrame, this, &NetCamView::updateSize);
-}
-
-void NetCamView::updateFrameSize()
-{
- QSize frameSize = selfVideoSurface->getFrameSize();
- float ratio = frameSize.width() / static_cast(frameSize.height());
- QRect videoRect = videoSurface->getRect();
- int frameHeight = videoRect.height() / 3.0f;
- //selfFrame->resize(frameHeight * ratio, frameHeight);
- selfFrame->setBoundary(videoRect, QSize(frameHeight * ratio, frameHeight));
+ QSize newSize = videoSurface->sizeHint();
+ QSizeF initialSize = initial;
+ selfFrame->setBoundary(newSize, initial, newSize.width() / initialSize.width(), newSize.height() / initialSize.height());
}
diff --git a/src/video/netcamview.h b/src/video/netcamview.h
index fdc2d2c51..3e610cd1b 100644
--- a/src/video/netcamview.h
+++ b/src/video/netcamview.h
@@ -21,6 +21,7 @@
#define NETCAMVIEW_H
#include
+#include "src/widget/tool/aspectratiowidget.h"
class QHBoxLayout;
struct vpx_image;
@@ -50,9 +51,10 @@ public slots:
void setShowMessages(bool show, bool notify = false);
protected:
+ void paintEvent(QPaintEvent* event);
void resizeEvent(QResizeEvent* event) final override;
-private slots:
+public slots:
void updateSize();
private:
@@ -63,6 +65,7 @@ private:
VideoSurface* selfVideoSurface;
MovableWidget* selfFrame;
QPushButton* button;
+ bool e = false;
};
#endif // NETCAMVIEW_H
diff --git a/src/video/videosurface.cpp b/src/video/videosurface.cpp
index 6c5fb78a6..f4b308cdb 100644
--- a/src/video/videosurface.cpp
+++ b/src/video/videosurface.cpp
@@ -21,14 +21,16 @@
#include "src/video/videoframe.h"
#include
#include
-
+#include
VideoSurface::VideoSurface(QWidget* parent)
- : QWidget{parent}
+ : AspectRatioWidget{parent}
, source{nullptr}
, frameLock{false}
, hasSubscribed{false}
{
- setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ qDebug() << "ddd" << minimumSize();
+ setMinimum(128);
+ setSizeHint(128, 128);
}
VideoSurface::VideoSurface(VideoSource *source, QWidget* parent)
@@ -51,7 +53,7 @@ void VideoSurface::setSource(VideoSource *src)
source = src;
subscribe();
}
-#include
+/*#include
QRect VideoSurface::getRect() const
{
// Fast lock
@@ -77,7 +79,7 @@ QRect VideoSurface::getRect() const
return QRect();
}
-QSize VideoSurface::getFrameSize()
+QSize VideoSurface::getFrameSize() const
{
// Fast lock
{
@@ -93,12 +95,7 @@ QSize VideoSurface::getFrameSize()
frameLock = false;
return frameSize;
-}
-
-QSize VideoSurface::sizeHint() const
-{
- return getRect().size();
-}
+}*/
void VideoSurface::subscribe()
{
@@ -140,6 +137,9 @@ void VideoSurface::onNewFrameAvailable(std::shared_ptr newFrame)
lastFrame = newFrame;
frameLock = false;
+ setRatio(lastFrame->getSize().width() / static_cast(lastFrame->getSize().height()));
+ ///setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
+ updateGeometry();
update();
emit drewNewFrame();
@@ -155,22 +155,22 @@ void VideoSurface::paintEvent(QPaintEvent*)
}
QPainter painter(this);
- //painter.fillRect(painter.viewport(), Qt::black);
+ painter.fillRect(painter.viewport(), QColor(193, 193, 193));
if (lastFrame)
{
- QSize frameSize = lastFrame->getSize();
+ /*QSize frameSize = lastFrame->getSize();
QRect rect = this->rect();
int width = frameSize.width()*rect.height()/frameSize.height();
rect.setLeft((rect.width()-width)/2);
- rect.setWidth(width);
+ rect.setWidth(width);*/
- QImage frame = lastFrame->toQImage(rect.size());
- painter.drawImage(rect, frame, frame.rect(), Qt::NoFormatConversion);
+ QImage frame = lastFrame->toQImage(rect().size());
+ painter.drawImage(rect(), frame, frame.rect(), Qt::NoFormatConversion);
//qDebug() << "VIDEO 2" << rect;
}
frameLock = false;
}
-#include
+/*#include
void VideoSurface::resizeEvent(QResizeEvent* event)
{
// Locks aspect ratio.
@@ -196,4 +196,4 @@ void VideoSurface::resizeEvent(QResizeEvent* event)
int width = ratio*event->size().width();
setMaximumHeight(width);
}
-}
+}*/
diff --git a/src/video/videosurface.h b/src/video/videosurface.h
index 584c39336..a882eb4c6 100644
--- a/src/video/videosurface.h
+++ b/src/video/videosurface.h
@@ -24,8 +24,9 @@
#include
#include
#include "src/video/videosource.h"
+#include "src/widget/tool/aspectratiowidget.h"
-class VideoSurface : public QWidget
+class VideoSurface : public AspectRatioWidget
{
Q_OBJECT
@@ -35,10 +36,8 @@ public:
~VideoSurface();
void setSource(VideoSource* src); //NULL is a valid option
- QRect getRect() const;
- QSize getFrameSize();
-
- virtual QSize sizeHint() const override;
+ //QRect getRect() const;
+ //QSize getFrameSize() const;
signals:
void drewNewFrame();
@@ -48,7 +47,7 @@ protected:
void unsubscribe();
virtual void paintEvent(QPaintEvent * event) final override;
- virtual void resizeEvent(QResizeEvent* event) final override;
+ //virtual void resizeEvent(QResizeEvent* event) final override;
private slots:
void onNewFrameAvailable(std::shared_ptr newFrame);
diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp
index d297d769c..be77b6495 100644
--- a/src/widget/form/chatform.cpp
+++ b/src/widget/form/chatform.cpp
@@ -119,6 +119,8 @@ ChatForm::ChatForm(Friend* chatFriend)
retranslateUi();
Translator::registerHandler(std::bind(&ChatForm::retranslateUi, this), this);
+
+ showNetcam();
}
ChatForm::~ChatForm()
@@ -1098,6 +1100,7 @@ void ChatForm::showNetcam()
if (!netcam)
netcam = new NetCamView();
+ //connect(Widget::getInstance(), &Widget::resized, netcam, &NetCamView::updateSize);
netcam->show(Core::getInstance()->getVideoSourceFromCall(callId), f->getDisplayedName());
connect(netcam, &NetCamView::showMessageClicked, this, &ChatForm::onShowMessagesClicked);
bodySplitter->insertWidget(0, netcam);
diff --git a/src/widget/tool/aspectratiowidget.cpp b/src/widget/tool/aspectratiowidget.cpp
new file mode 100644
index 000000000..775d7ddc5
--- /dev/null
+++ b/src/widget/tool/aspectratiowidget.cpp
@@ -0,0 +1,131 @@
+/*
+ Copyright © 2015 by The qTox Project
+
+ This file is part of qTox, a Qt-based graphical interface for Tox.
+
+ qTox is libre software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ qTox is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with qTox. If not, see .
+*/
+
+#include "aspectratiowidget.h"
+#include
+
+AspectRatioWidget::AspectRatioWidget(QWidget *parent)
+ : QWidget(parent)
+ , ratioMode{RespectWidth}
+ , ratioWidth{QWIDGETSIZE_MAX}
+{
+ setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
+ setRatio(1.33f);
+ //setSizeHint(64, 64 / 1.33f);
+ size_ = QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
+}
+
+float AspectRatioWidget::getRatio() const
+{
+ return ratio;
+}
+
+bool AspectRatioWidget::aspectRatioRespected() const
+{
+ int w = static_cast(width() / ratio);
+ return height() == w - 1 || height() == w || height() == w + 1;
+}
+#include
+QSize AspectRatioWidget::sizeHint() const
+{
+ //return QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
+ return size_;
+ switch (ratioMode)
+ {
+ case RespectWidth:
+ return QSize(ratioWidth, width() / ratio);
+ case RespectHeight:
+ return QSize(height() * ratio, height());
+ case MaximizeSize:
+ default:
+ return QSize(ratioWidth, ratioWidth);
+ }
+}
+#include
+void AspectRatioWidget::setSizeHint(int width, int height)
+{
+ size_ = QSize(width, height);
+}
+
+void AspectRatioWidget::setMinimum(int minimumHieght)
+{
+ setMinimumSize(minimumHieght * ratio, minimumHieght);
+}
+
+void AspectRatioWidget::setRatio(float r)
+{
+ if (ratio == r)
+ return;
+
+ ratio = r;
+ setMinimum(minimumHeight());
+}
+
+void AspectRatioWidget::setRatioMode(RatioMode mode)
+{
+ ratioMode = mode;
+
+ if (sizeHint().width() > 1)
+ setMaximumWidth(sizeHint().width());
+
+ updateGeometry();
+}
+
+void AspectRatioWidget::setRatioWidth(int w)
+{
+ ratioWidth = w;
+}
+
+void AspectRatioWidgetList::updateAll()
+{
+ if (isEmpty())
+ return;
+
+ // Maximize the size of all of them, so that they will be equal.
+ for (AspectRatioWidget* aspectWidget : *this)
+ {
+ aspectWidget->setUpdatesEnabled(false);
+ aspectWidget->setRatioMode(AspectRatioWidget::MaximizeSize);
+ }
+
+ // Need this to trigger layout recalculations.
+ qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
+
+ // Now update heights.
+ for (AspectRatioWidget* aspectWidget : *this)
+ aspectWidget->setRatioMode(AspectRatioWidget::RespectWidth);
+
+ qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+
+ // if height does not fit, then decrease width.
+ // Query only one. Assumes that all of them are next to each other.
+ if (!at(0)->aspectRatioRespected())
+ {
+ for (AspectRatioWidget* aspectWidget : *this)
+ aspectWidget->setRatioMode(AspectRatioWidget::RespectHeight);
+
+ qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
+ }
+
+ for (AspectRatioWidget* aspectWidget : *this)
+ {
+ aspectWidget->setUpdatesEnabled(true);
+ aspectWidget->update();
+ }
+}
diff --git a/src/widget/tool/aspectratiowidget.h b/src/widget/tool/aspectratiowidget.h
new file mode 100644
index 000000000..df17595d2
--- /dev/null
+++ b/src/widget/tool/aspectratiowidget.h
@@ -0,0 +1,66 @@
+/*
+ Copyright © 2015 by The qTox Project
+
+ This file is part of qTox, a Qt-based graphical interface for Tox.
+
+ qTox is libre software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ qTox is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with qTox. If not, see .
+*/
+
+#ifndef ASPECTRATIOWIDGET_H
+#define ASPECTRATIOWIDGET_H
+
+#include
+
+class AspectRatioWidgetList;
+
+class AspectRatioWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit AspectRatioWidget(QWidget *parent = 0);
+ float getRatio() const;
+ bool aspectRatioRespected() const;
+ virtual QSize sizeHint() const final override;
+ void setSizeHint(int width, int height);
+ void setMinimum(int minimumHieght);
+
+protected:
+ enum RatioMode
+ {
+ RespectWidth = 0,
+ RespectHeight = 1,
+ MaximizeSize = 2
+ };
+
+ void setRatio(float r);
+ void setRatioMode(RatioMode mode);
+ void setRatioWidth(int w = QWIDGETSIZE_MAX);
+
+ friend class AspectRatioWidgetList;
+
+private:
+ RatioMode ratioMode;
+ int ratioWidth;
+ float ratio;
+ QSize size_;
+};
+
+class AspectRatioWidgetList : public QVector
+{
+public:
+ // Must update all simultaneously.
+ void updateAll();
+};
+
+#endif // ASPECTRATIOWIDGET_H
diff --git a/src/widget/tool/movablewidget.cpp b/src/widget/tool/movablewidget.cpp
index 93d8a74e6..09f46d59b 100644
--- a/src/widget/tool/movablewidget.cpp
+++ b/src/widget/tool/movablewidget.cpp
@@ -21,33 +21,45 @@
#include
#include
#include
+#include
MovableWidget::MovableWidget(QWidget *parent)
- : QWidget(parent)
+ : AspectRatioWidget(parent)
{
-
+ setMouseTracking(true);
+ setRatioWidth(64);
+ setMinimum(64);
+ setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
+ resize(minimumSize());
+ actualSize = minimumSize();
}
-#include
-void MovableWidget::setBoundary(const QRect& boundary, QSize size)
+
+void MovableWidget::setBoundary(QSize parentSize, QSize oldSize, float xPercent, float yPercent)
{
- int widthEdge = boundaryRect.x() - width();
- checkBoundaryLeft(widthEdge);
- int widthRange = abs(widthEdge) * 2 + boundaryRect.width() - width();
- float xPercent = static_cast(x() - widthEdge) / widthRange;
- qDebug() << xPercent << x() - widthEdge << widthRange;
- float yPercent = static_cast(y()) / (boundaryRect.height() - height());
+ // NOTE: When called, the parentWidget has not resized yet.
- if (size.isValid())
- resize(size);
+ // Prevent division with 0.
+ if (width() == oldSize.width() || height() == oldSize.height())
+ return;
- boundaryRect = boundary;
- widthEdge = boundaryRect.x() - width();
- checkBoundaryLeft(widthEdge);
+ float percentageX = x() / static_cast(oldSize.width() - width());
+ float percentageY = y() / static_cast(oldSize.height() - height());
- QPoint moveTo = pos();
- moveTo.setX((abs(widthEdge) * 2 + boundaryRect.width() - width()) * xPercent);
- moveTo.setY((boundaryRect.height() - height()) * yPercent);
- checkBoundary(moveTo);
+ actualSize.setWidth(actualSize.width() * xPercent);
+ actualSize.setHeight(actualSize.height() * yPercent);
+
+ if (actualSize.width() == 0)
+ actualSize.setWidth(1);
+
+ if (actualSize.height() == 0)
+ actualSize.setHeight(1);
+
+ resize(QSize(round(actualSize.width()), round(actualSize.height())));
+ updateGeometry();
+
+ actualPos = QPointF(percentageX * (parentSize.width() - width()), percentageY * (parentSize.height() - height()));
+
+ QPoint moveTo = QPoint(round(actualPos.x()), round(actualPos.y()));
move(moveTo);
}
@@ -55,27 +67,153 @@ void MovableWidget::mousePressEvent(QMouseEvent* event)
{
if (event->buttons() & Qt::LeftButton)
{
- moving = true;
+ if (!(mode & Resize))
+ mode |= Moving;
+
lastPoint = event->globalPos();
}
}
void MovableWidget::mouseMoveEvent(QMouseEvent* event)
{
- if (moving)
+ if (mode & Moving)
{
QPoint moveTo = pos() - (lastPoint - event->globalPos());
checkBoundary(moveTo);
move(moveTo);
lastPoint = event->globalPos();
+
+ actualPos = pos();
+ }
+ else
+ {
+ if (!(event->buttons() & Qt::LeftButton))
+ {
+ if (event->x() < 6)
+ mode |= ResizeLeft;
+ else
+ mode &= ~ResizeLeft;
+
+ if (event->y() < 6)
+ mode |= ResizeUp;
+ else
+ mode &= ~ResizeUp;
+
+ if (event->x() > width() - 6)
+ mode |= ResizeRight;
+ else
+ mode &= ~ResizeRight;
+
+ if (event->y() > height() - 6)
+ mode |= ResizeDown;
+ else
+ mode &= ~ResizeDown;
+ }
+
+ if (mode & Resize)
+ {
+ const Modes ResizeUpRight = ResizeUp | ResizeRight;
+ const Modes ResizeUpLeft = ResizeUp | ResizeLeft;
+ const Modes ResizeDownRight = ResizeDown | ResizeRight;
+ const Modes ResizeDownLeft = ResizeDown | ResizeLeft;
+
+ if ((mode & ResizeUpRight) == ResizeUpRight || (mode & ResizeDownLeft) == ResizeDownLeft)
+ setCursor(Qt::SizeBDiagCursor);
+ else if ((mode & ResizeUpLeft) == ResizeUpLeft || (mode & ResizeDownRight) == ResizeDownRight)
+ setCursor(Qt::SizeFDiagCursor);
+ else if (mode & (ResizeLeft | ResizeRight))
+ setCursor(Qt::SizeHorCursor);
+ else
+ setCursor(Qt::SizeVerCursor);
+
+ if (event->buttons() & Qt::LeftButton)
+ {
+ QPoint lastPosition = pos();
+ QPoint displacement = lastPoint - event->globalPos();
+ QSize lastSize = size();
+
+
+ if (mode & ResizeUp)
+ {
+ lastSize.setHeight(height() + displacement.y());
+
+ if (lastSize.height() > parentWidget()->height() / 2)
+ lastPosition.setY(y() - displacement.y() + (lastSize.height() - parentWidget()->height() / 2));
+ else
+ lastPosition.setY(y() - displacement.y());
+ }
+
+ if (mode & ResizeLeft)
+ {
+ lastSize.setWidth(width() + displacement.x());
+ if (lastSize.width() > parentWidget()->width() / 2)
+ lastPosition.setX(x() - displacement.x() + (lastSize.width() - parentWidget()->width() / 2));
+ else
+ lastPosition.setX(x() - displacement.x());
+ }
+
+ if (mode & ResizeRight)
+ lastSize.setWidth(width() - displacement.x());
+
+ if (mode & ResizeDown)
+ lastSize.setHeight(height() - displacement.y());
+
+ if (lastSize.height() > parentWidget()->height() / 2)
+ lastSize.setHeight(parentWidget()->height() / 2);
+
+ if (lastSize.width() > parentWidget()->width() / 2)
+ lastSize.setWidth(parentWidget()->width() / 2);
+
+ if (mode & (ResizeLeft | ResizeRight))
+ {
+ if (mode & (ResizeUp | ResizeDown))
+ {
+ int height = lastSize.width() / getRatio();
+
+ if (!(mode & ResizeDown))
+ lastPosition.setY(lastPosition.y() - (height - lastSize.height()));
+
+ resize(lastSize.width(), height);
+
+ if (lastSize.width() < minimumWidth())
+ lastPosition.setX(pos().x());
+
+ if (height < minimumHeight())
+ lastPosition.setY(pos().y());
+ }
+ else
+ {
+ resize(lastSize.width(), lastSize.width() / getRatio());
+ }
+ }
+ else
+ {
+ resize(lastSize.height() * getRatio(), lastSize.height());
+ }
+
+ updateGeometry();
+
+ checkBoundary(lastPosition);
+
+ move(lastPosition);
+
+ lastPoint = event->globalPos();
+ actualSize = size();
+ actualPos = pos();
+ }
+ }
+ else
+ {
+ unsetCursor();
+ }
}
}
void MovableWidget::mouseReleaseEvent(QMouseEvent* event)
{
if (!(event->buttons() & Qt::LeftButton))
- moving = false;
+ mode = 0;
}
void MovableWidget::mouseDoubleClickEvent(QMouseEvent* event)
@@ -94,12 +232,17 @@ void MovableWidget::mouseDoubleClickEvent(QMouseEvent* event)
setGraphicsEffect(nullptr);
}
}
+#include
+void MovableWidget::paintEvent(QPaintEvent*)
+{
+ QPainter painter(this);
+ painter.setBrush(Qt::black);
+ painter.drawRect(rect());
+ //qDebug() << rect();
+}
void MovableWidget::checkBoundary(QPoint& point) const
{
- if (boundaryRect.isNull())
- return;
-
int x1, y1, x2, y2;
boundaryRect.getCoords(&x1, &y1, &x2, &y2);
@@ -109,14 +252,14 @@ void MovableWidget::checkBoundary(QPoint& point) const
// Video boundary.
- if (point.y() + height() x2)
point.setX(x2);
if (point.y() > y2)
- point.setY(y2);
+ point.setY(y2);*/
// Parent boundary.
if (point.y() < 0)
@@ -134,6 +277,6 @@ void MovableWidget::checkBoundaryLeft(int &x) const
if (x < 0)
x = 0;
- if (x + width() < boundaryRect.x())
- x = boundaryRect.x() - width();
+ /*if (x + width() < boundaryRect.x())
+ x = boundaryRect.x() - width();*/
}
diff --git a/src/widget/tool/movablewidget.h b/src/widget/tool/movablewidget.h
index 4d6d4920d..1ba7ad904 100644
--- a/src/widget/tool/movablewidget.h
+++ b/src/widget/tool/movablewidget.h
@@ -21,29 +21,42 @@
#define MOVABLEWIDGET_H
#include
+#include "aspectratiowidget.h"
-class MovableWidget : public QWidget
+class MovableWidget : public AspectRatioWidget
{
public:
MovableWidget(QWidget* parent);
- void setBoundary(const QRect& boundary, QSize size = QSize());
+ void setBoundary(QSize parentSize, QSize oldSize, float xPercent, float yPercent);
protected:
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
void mouseDoubleClickEvent(QMouseEvent* event);
+ void paintEvent(QPaintEvent*);
private:
void checkBoundary(QPoint& point) const;
- void checkBoundaryTop(int &x) const;
- void checkBoundaryBottom(int &x) const;
void checkBoundaryLeft(int &x) const;
- void checkBoundaryRight(int &x) const;
- bool moving = false;
+ typedef uint8_t Modes;
+
+ enum Mode : Modes
+ {
+ Moving = 0x01,
+ ResizeLeft = 0x02,
+ ResizeRight = 0x04,
+ ResizeUp = 0x08,
+ ResizeDown = 0x10,
+ Resize = ResizeLeft | ResizeRight | ResizeUp | ResizeDown
+ };
+
+ Modes mode = 0;
QPoint lastPoint;
QRect boundaryRect;
+ QSizeF actualSize;
+ QPointF actualPos;
};
#endif // MOVABLEWIDGET_H
diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp
index eb097bb95..f73dc5182 100644
--- a/src/widget/widget.cpp
+++ b/src/widget/widget.cpp
@@ -210,6 +210,7 @@ void Widget::init()
// disable proportional scaling
ui->mainSplitter->setStretchFactor(0,0);
ui->mainSplitter->setStretchFactor(1,1);
+ qDebug() << ui->mainSplitter->widget(0)->sizePolicy();
onStatusSet(Status::Offline);