qTox  Version: nightly | Commit: bc751c8e1cac455f9690654fcfe0f560d2d7dfdd
chatlinecontentproxy.cpp
Go to the documentation of this file.
1 /*
2  Copyright © 2014-2019 by The qTox Project Contributors
3 
4  This file is part of qTox, a Qt-based graphical interface for Tox.
5 
6  qTox is libre software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  qTox is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with qTox. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "chatlinecontentproxy.h"
22 #include <QDebug>
23 #include <QLayout>
24 #include <QPainter>
25 #include <QWidget>
26 
36  int minWidth, float widthInPercent)
37  : widthPercent(widthInPercent)
38  , widthMin(minWidth)
39  , widgetType{type}
40 {
41  proxy = new QGraphicsProxyWidget(this);
42  proxy->setWidget(widget);
43 }
44 
45 ChatLineContentProxy::ChatLineContentProxy(QWidget* widget, int minWidth, float widthInPercent)
46  : ChatLineContentProxy(widget, GenericType, minWidth, widthInPercent)
47 {
48 }
49 
50 ChatLineContentProxy::ChatLineContentProxy(FileTransferWidget* widget, int minWidth, float widthInPercent)
51  : ChatLineContentProxy(widget, FileTransferWidgetType, minWidth, widthInPercent)
52 {
53 }
54 
56 {
57  QRectF result = proxy->boundingRect();
58  result.setHeight(result.height() + 5);
59  return result;
60 }
61 
62 void ChatLineContentProxy::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
63  QWidget* widget)
64 {
65  painter->setClipRect(boundingRect());
66  proxy->paint(painter, option, widget);
67 }
68 
70 {
71  return 7.0;
72 }
73 
75 {
76  return proxy->widget();
77 }
78 
80 {
81  prepareGeometryChange();
82  proxy->widget()->setFixedWidth(qMax(static_cast<int>(width * widthPercent), widthMin));
83 }
84 
86 {
87  return widgetType;
88 }
ChatLineContentProxy::widgetType
const ChatLineContentProxyType widgetType
Definition: chatlinecontentproxy.h:58
ChatLineContentProxy::widthPercent
float widthPercent
Definition: chatlinecontentproxy.h:56
FileTransferWidget
Definition: filetransferwidget.h:37
ChatLineContentProxy::getWidgetType
ChatLineContentProxyType getWidgetType() const
Definition: chatlinecontentproxy.cpp:85
ChatLineContentProxy::setWidth
void setWidth(qreal width) override
Definition: chatlinecontentproxy.cpp:79
ChatLineContentProxy::ChatLineContentProxyType
ChatLineContentProxyType
Type tag to avoid dynamic_cast of contained QWidget*.
Definition: chatlinecontentproxy.h:32
ChatLineContentProxy::boundingRect
QRectF boundingRect() const override
Definition: chatlinecontentproxy.cpp:55
ChatLineContentProxy::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
Definition: chatlinecontentproxy.cpp:62
filetransferwidget.h
ChatLineContentProxy::getAscent
qreal getAscent() const override
Definition: chatlinecontentproxy.cpp:69
ChatLineContentProxy::getWidget
QWidget * getWidget() const
Definition: chatlinecontentproxy.cpp:74
ChatLineContent::type
int type() const final
Definition: chatlinecontent.cpp:33
chatlinecontentproxy.h
ChatLineContentProxy
Definition: chatlinecontentproxy.h:27
ChatLineContentProxy::ChatLineContentProxy
ChatLineContentProxy(QWidget *widget, int minWidth, float widthInPercent=1.0f)
Definition: chatlinecontentproxy.cpp:45
ChatLineContentProxy::proxy
QGraphicsProxyWidget * proxy
Definition: chatlinecontentproxy.h:55
ChatLineContentProxy::widthMin
int widthMin
Definition: chatlinecontentproxy.h:57