Add preview window action

This commit is contained in:
杨万青 2015-07-09 20:41:15 +08:00
parent 58ad246ddd
commit 39395ba0a9
33 changed files with 259 additions and 311 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 317 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -1,278 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="32"
height="32"
id="svg6860"
inkscape:version="0.48.4 r9939"
sodipodi:docname="multitasking-view.svg">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1440"
inkscape:window-height="845"
id="namedview46"
showgrid="true"
inkscape:zoom="9.921875"
inkscape:cx="20.08189"
inkscape:cy="16"
inkscape:window-x="0"
inkscape:window-y="30"
inkscape:window-maximized="1"
inkscape:current-layer="svg6860">
<inkscape:grid
type="xygrid"
id="grid3316" />
</sodipodi:namedview>
<defs
id="defs6862">
<linearGradient
id="linearGradient3924-0">
<stop
id="stop3926-6"
style="stop-color:#ffffff;stop-opacity:1"
offset="0" />
<stop
id="stop3928-3"
style="stop-color:#ffffff;stop-opacity:0.23529412"
offset="0.06316455" />
<stop
id="stop3930-2"
style="stop-color:#ffffff;stop-opacity:0.15686275"
offset="0.95056331" />
<stop
id="stop3932-62"
style="stop-color:#ffffff;stop-opacity:0.39215687"
offset="1" />
</linearGradient>
<radialGradient
cx="4.9929786"
cy="43.5"
r="2.5"
fx="4.9929786"
fy="43.5"
id="radialGradient2976"
xlink:href="#linearGradient3688-166-749-6"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.003784,0,0,1.4,27.98813,-17.4)" />
<linearGradient
id="linearGradient3688-166-749-6">
<stop
id="stop2883-8"
style="stop-color:#181818;stop-opacity:1"
offset="0" />
<stop
id="stop2885-3"
style="stop-color:#181818;stop-opacity:0"
offset="1" />
</linearGradient>
<radialGradient
cx="4.9929786"
cy="43.5"
r="2.5"
fx="4.9929786"
fy="43.5"
id="radialGradient2978"
xlink:href="#linearGradient3688-464-309-7"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.003784,0,0,1.4,-20.01187,-104.4)" />
<linearGradient
id="linearGradient3688-464-309-7">
<stop
id="stop2889-0"
style="stop-color:#181818;stop-opacity:1"
offset="0" />
<stop
id="stop2891-66"
style="stop-color:#181818;stop-opacity:0"
offset="1" />
</linearGradient>
<linearGradient
x1="25.058096"
y1="47.027729"
x2="25.058096"
y2="39.999443"
id="linearGradient2980"
xlink:href="#linearGradient3702-501-757-3"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient3702-501-757-3">
<stop
id="stop2895-3"
style="stop-color:#181818;stop-opacity:0"
offset="0" />
<stop
id="stop2897-28"
style="stop-color:#181818;stop-opacity:1"
offset="0.5" />
<stop
id="stop2899-8"
style="stop-color:#181818;stop-opacity:0"
offset="1" />
</linearGradient>
<linearGradient
id="linearGradient5803-6-2">
<stop
id="stop5805-7-1"
style="stop-color:#ffffff;stop-opacity:1;"
offset="0" />
<stop
id="stop5807-8-5"
style="stop-color:#e6f4f8;stop-opacity:1;"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3924-0"
id="linearGradient3215"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.62162164,0,0,0.62162164,1.0810794,2.0810903)"
x1="23.99999"
y1="4.999989"
x2="23.99999"
y2="43" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-8-3-5-6-6-5"
id="radialGradient3275-7"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0,3.8461954,-7.4743331,0,90.95547,-34.119923)"
cx="7.7392125"
cy="9.9571075"
fx="7.2089825"
fy="9.9571075"
r="12.671875" />
<linearGradient
id="linearGradient2867-449-88-871-390-598-476-591-434-148-57-177-8-3-5-6-6-5">
<stop
id="stop3750-1-0-6-9-9-6"
style="stop-color:#90dbec;stop-opacity:1"
offset="0" />
<stop
id="stop3752-3-7-8-3-5-6"
style="stop-color:#55c1ec;stop-opacity:1"
offset="0.26238" />
<stop
id="stop3754-1-8-5-8-5-6"
style="stop-color:#3689e6;stop-opacity:1"
offset="0.704952" />
<stop
id="stop3756-1-6-3-7-3-1"
style="stop-color:#2b63a0;stop-opacity:1"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient5803-6-2"
id="linearGradient3324"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.4265442,0,0,0.41469579,-54.033003,2.5228637)"
x1="167.98311"
y1="13.398731"
x2="167.98311"
y2="54.780239" />
</defs>
<metadata
id="metadata6865">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
style="display:inline"
id="g2036-2"
transform="matrix(0.6999997,0,0,0.3333336,-0.8000002,15.33333)">
<g
style="opacity:0.4"
id="g3712-3"
transform="matrix(1.052632,0,0,1.285713,-1.263158,-13.42854)">
<rect
style="fill:url(#radialGradient2976);fill-opacity:1;stroke:none"
id="rect2801-0"
y="40"
x="38"
height="7"
width="5" />
<rect
style="fill:url(#radialGradient2978);fill-opacity:1;stroke:none"
id="rect3696-2"
transform="scale(-1,-1)"
y="-47"
x="-10"
height="7"
width="5" />
<rect
style="fill:url(#linearGradient2980);fill-opacity:1;stroke:none"
id="rect3700-1"
y="40"
x="10"
height="7.0000005"
width="28" />
</g>
</g>
<rect
style="color:#000000;fill:url(#radialGradient3275-7);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:0.99999994000000003;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect5505"
y="4.5"
x="3.4999993"
ry="2"
rx="2"
height="25"
width="25" />
<rect
style="opacity:0.5;fill:none;stroke:url(#linearGradient3215);stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect6741-7-4"
y="5.5"
x="4.499999"
ry="1"
rx="1"
height="23"
width="23" />
<rect
style="opacity:0.40000000000000002;color:#000000;fill:none;stroke:#003164;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="rect5505-6"
y="4.5"
x="3.4999993"
ry="2"
rx="2"
height="25"
width="25" />
<path
sodipodi:type="inkscape:offset"
inkscape:radius="0.9900791"
inkscape:original="M 6.59375 9 C 6.2613505 9 6 9.2705839 6 9.59375 L 6 15.40625 C 6 15.729417 6.2613505 16 6.59375 16 L 14.40625 16 C 14.73865 16 15 15.729417 15 15.40625 L 15 9.59375 C 15 9.2705839 14.73865 9 14.40625 9 L 6.59375 9 z M 18.53125 10 C 18.235784 10 18 10.303704 18 10.65625 L 18 16.34375 C 18 16.696297 18.235784 17 18.53125 17 L 25.46875 17 C 25.764216 17 26 16.696297 26 16.34375 L 26 10.65625 C 26 10.303704 25.764216 10 25.46875 10 L 18.53125 10 z M 10.71875 19 C 10.312483 19 10 19.347091 10 19.75 L 10 26.25 C 10 26.652909 10.312483 27 10.71875 27 L 20.28125 27 C 20.687518 27 21 26.652909 21 26.25 L 21 19.75 C 21 19.347091 20.687518 19 20.28125 19 L 10.71875 19 z "
style="opacity:0.14999999999999999;color:#000000;fill:#0974ae;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path3400"
d="M 6.59375,8 C 5.7240463,8 5,8.7367868 5,9.59375 l 0,5.8125 C 5,16.263213 5.7240481,17 6.59375,17 l 7.8125,0 C 15.275952,17 16,16.263212 16,15.40625 l 0,-5.8125 C 16,8.7367879 15.275953,8 14.40625,8 l -7.8125,0 z m 11.9375,1 C 17.557328,9 17,9.8622584 17,10.65625 l 0,5.6875 C 17,17.137741 17.55733,18 18.53125,18 l -7.8125,0 C 9.7485722,18 9,18.835176 9,19.75 l 0,6.5 C 9,27.164824 9.7485722,28 10.71875,28 l 9.5625,0 C 21.251427,28 22,27.164823 22,26.25 l 0,-6.5 C 22,18.835177 21.251427,18 20.28125,18 l 5.1875,0 C 26.44267,18 27,17.137741 27,16.34375 l 0,-5.6875 C 27,9.8622584 26.442672,9 25.46875,9 l -6.9375,0 z" />
<path
inkscape:connector-curvature="0"
style="color:#000000;fill:#0935ae;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate;opacity:0.29999999999999999"
d="M 6.59375,9 C 6.2613505,9 6,9.2705839 6,9.59375 l 0,5.8125 C 6,15.729417 6.2613505,16 6.59375,16 l 7.8125,0 C 14.73865,16 15,15.729417 15,15.40625 l 0,-5.8125 C 15,9.2705839 14.73865,9 14.40625,9 l -7.8125,0 z m 11.9375,1 C 18.235784,10 18,10.303704 18,10.65625 l 0,5.6875 C 18,16.696297 18.235784,17 18.53125,17 l 6.9375,0 C 25.764216,17 26,16.696297 26,16.34375 l 0,-5.6875 C 26,10.303704 25.764216,10 25.46875,10 l -6.9375,0 z m -7.8125,9 C 10.312483,19 10,19.347091 10,19.75 l 0,6.5 c 0,0.402909 0.312483,0.75 0.71875,0.75 l 9.5625,0 C 20.687518,27 21,26.652909 21,26.25 l 0,-6.5 C 21,19.347091 20.687518,19 20.28125,19 l -9.5625,0 z"
id="path3322-2" />
<path
style="color:#000000;fill:url(#linearGradient3324);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="M 6.59375 8 C 6.2613505 8 6 8.2705839 6 8.59375 L 6 14.40625 C 6 14.729417 6.2613505 15 6.59375 15 L 14.40625 15 C 14.73865 15 15 14.729417 15 14.40625 L 15 8.59375 C 15 8.2705839 14.73865 8 14.40625 8 L 6.59375 8 z M 18.53125 9 C 18.235784 9 18 9.303704 18 9.65625 L 18 15.34375 C 18 15.696297 18.235784 16 18.53125 16 L 25.46875 16 C 25.764216 16 26 15.696297 26 15.34375 L 26 9.65625 C 26 9.303704 25.764216 9 25.46875 9 L 18.53125 9 z M 10.71875 18 C 10.312483 18 10 18.347091 10 18.75 L 10 25.25 C 10 25.652909 10.312483 26 10.71875 26 L 20.28125 26 C 20.687518 26 21 25.652909 21 25.25 L 21 18.75 C 21 18.347091 20.687518 18 20.28125 18 L 10.71875 18 z "
id="path3322" />
</svg>

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 902 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 347 B

View File

@ -37,7 +37,8 @@ SOURCES += \
src/dockpluginmanager.cpp\
src/DBus/dbusmenumanager.cpp \
src/DBus/dbusmenu.cpp \
src/Widgets/apppreviews.cpp
src/Widgets/apppreviews.cpp \
src/Widgets/closebutton.cpp
HEADERS += \
src/abstractdockitem.h \
@ -67,7 +68,8 @@ HEADERS += \
src/DBus/dbusmenu.h \
src/dockpluginmanager.h \
src/dockconstants.h \
src/Widgets/apppreviews.h
src/Widgets/apppreviews.h \
src/Widgets/closebutton.h
RESOURCES += \
images.qrc \

View File

@ -1,23 +1,7 @@
<RCC>
<qresource prefix="/test">
<file>Resources/images/brasero.png</file>
<file>Resources/images/crossover.png</file>
<file>Resources/images/d-feet.png</file>
<file>Resources/images/deepin-multitasking-view.svg</file>
<file>Resources/images/display-im6.q16.png</file>
<file>Resources/images/eog.png</file>
<file>Resources/images/file-roller.png</file>
<file>Resources/images/gcr-gnupg.png</file>
<file>Resources/images/gcr-key-pair.png</file>
<file>Resources/images/gcr-key.png</file>
<file>Resources/images/gcr-password.png</file>
<file>Resources/images/gcr-smart-card.png</file>
<file>Resources/images/google-chrome.png</file>
<file>Resources/images/gparted.png</file>
<file>Resources/images/inkscape.png</file>
<file>Resources/images/QtProject-qtcreator.png</file>
<file>Resources/images/remmina.png</file>
<file>Resources/images/terminator.png</file>
<file>Resources/images/vim.png</file>
<qresource prefix="/">
<file>Resources/images/close_hover.png</file>
<file>Resources/images/close_press.png</file>
<file>Resources/images/close_normal.png</file>
</qresource>
</RCC>

View File

@ -154,9 +154,7 @@ void Panel::slotRemoveAppItem(const QString &id)
AppItem *tmpItem = qobject_cast<AppItem *>(tmpList.at(i));
if (tmpItem->itemId() == id)
{
//TODO,remove from layout
leftLayout->removeItem(i);
qWarning() << "=====" << leftLayout->getItemCount();
return;
}
}

View File

@ -16,6 +16,10 @@ AppItem::AppItem(QWidget *parent) :
QWidget *AppItem::getContents()
{
AppPreviews *preview = new AppPreviews();
connect(preview,&AppPreviews::mouseEntered,this,&AppItem::cancelHide);
connect(preview,&AppPreviews::mouseExited,[=](){hidePreview();});
connect(preview,&AppPreviews::sizeChanged,this,&AppItem::resizePreview);
QJsonArray tmpArray = QJsonDocument::fromJson(m_itemData.xidsJsonString.toUtf8()).array();
if (m_itemData.isActived && !tmpArray.isEmpty())
{

View File

@ -1,5 +1,43 @@
#include "apppreviews.h"
AppPreviewFrame::AppPreviewFrame(QWidget *preview, const QString &title, int xid, QWidget *parent) : QWidget(parent),xidValue(xid)
{
addPreview(preview);
setTitle(title);
addCloseButton();
}
void AppPreviewFrame::addPreview(QWidget *p)
{
this->resize(p->size());
p->setParent(this);
p->move(0,0);
}
void AppPreviewFrame::setTitle(const QString &t)
{
QLabel *titleLabel = new QLabel(this);
QFontMetrics fm(titleLabel->font());
titleLabel->setText(fm.elidedText(t,Qt::ElideRight,width() * 4 / 5));
titleLabel->setStyleSheet("color:white");
titleLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
titleLabel->resize(width() * 4 / 5,20);
titleLabel->move(width() / 5 / 2,height() - titleLabel->height());
}
void AppPreviewFrame::mousePressEvent(QMouseEvent *)
{
emit activate(xidValue);
}
void AppPreviewFrame::addCloseButton()
{
CloseButton *cb = new CloseButton(this);
connect(cb,&CloseButton::clicked,[=](){close(this->xidValue);});
cb->resize(28,28);
cb->move(width() - cb->width(),0);
}
AppPreviews::AppPreviews(QWidget *parent) : QWidget(parent)
{
m_mainLayout = new QHBoxLayout(this);
@ -14,8 +52,13 @@ void AppPreviews::addItem(const QString &title, int xid)
return;
m_xidList.append(xid);
WindowPreview * preview = new WindowPreview(xid);
// QWidget *preview = new QWidget();
preview->resize(Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
m_mainLayout->addWidget(preview);
AppPreviewFrame *f = new AppPreviewFrame(preview,title,xid);
connect(f,&AppPreviewFrame::close,this,&AppPreviews::removePreview);
connect(f,&AppPreviewFrame::activate,this,&AppPreviews::activatePreview);
m_mainLayout->addWidget(f);
resize(m_mainLayout->count() * Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
}
@ -25,7 +68,50 @@ void AppPreviews::setTitle(const QString &title)
titleLabel->setObjectName("DockAppTitle");
titleLabel->setAlignment(Qt::AlignCenter);
m_mainLayout->addWidget(titleLabel);
int textWidth = titleLabel->fontMetrics().boundingRect(titleLabel->text()).width();
QFontMetrics fm(titleLabel->font());
int textWidth = fm.width(title);
resize(textWidth < 80 ? 80 : textWidth,20);
}
void AppPreviews::enterEvent(QEvent *)
{
emit mouseEntered();
}
void AppPreviews::leaveEvent(QEvent *)
{
if (isClosing)
{
isClosing = false;
return;
}
emit mouseExited();
}
void AppPreviews::removePreview(int xid)
{
isClosing = true;
m_mainLayout->removeWidget(qobject_cast<AppPreviewFrame *>(sender()));
sender()->deleteLater();
m_clientManager->CloseWindow(xid);
if (m_mainLayout->count() <= 0)
{
emit mouseExited();
return;
}
resize(m_mainLayout->count() * Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
emit sizeChanged();
}
void AppPreviews::activatePreview(int xid)
{
m_clientManager->ActiveWindow(xid);
}

View File

@ -5,9 +5,33 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
#include "DBus/dbusclientmanager.h"
#include "windowpreview.h"
#include "closebutton.h"
#include "../dockconstants.h"
class AppPreviewFrame : public QWidget
{
Q_OBJECT
public:
explicit AppPreviewFrame(QWidget *preview, const QString &title,int xid, QWidget *parent=0);
void addPreview(QWidget *p);
void setTitle(const QString &t);
protected:
void mousePressEvent(QMouseEvent *);
signals:
void close(int xid);
void activate(int xid);
private:
void addCloseButton();
private:
int xidValue;
};
class AppPreviews : public QWidget
{
Q_OBJECT
@ -16,13 +40,25 @@ public:
void addItem(const QString &title,int xid);
void setTitle(const QString &title);
protected:
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
signals:
void mouseEntered();
void mouseExited();
void sizeChanged();
public slots:
void removePreview(int xid);
void activatePreview(int xid);
private:
DBusClientManager *m_clientManager = new DBusClientManager(this);
QHBoxLayout *m_mainLayout = NULL;
QList<int> m_xidList;
bool isClosing = false;
};
#endif // APPPREVIEWS_H

View File

@ -88,6 +88,12 @@ void ArrowRectangle::delayHide(int interval)
m_destroyTimer->start(interval);
}
void ArrowRectangle::cancelHide()
{
if (m_destroyTimer)
m_destroyTimer->stop();
}
void ArrowRectangle::setContent(QWidget *content)
{
if (!content)
@ -102,6 +108,7 @@ void ArrowRectangle::setContent(QWidget *content)
m_content = content;
m_content->setParent(this);
resizeWithContent();
switch(arrowDirection)
{
case ArrowLeft:
@ -119,6 +126,26 @@ void ArrowRectangle::setContent(QWidget *content)
}
}
void ArrowRectangle::resizeWithContent()
{
if (m_content)
{
switch(arrowDirection)
{
case ArrowLeft:
case ArrowRight:
resize(m_content->width() + m_margin * 2 + arrowHeight,m_content->height() + m_margin * 2);
break;
case ArrowTop:
case ArrowBottom:
resize(m_content->width() + m_margin * 2,m_content->height() + m_margin * 2 + arrowHeight);
break;
}
}
repaint();
}
void ArrowRectangle::destroyContent()
{
if (m_content)

View File

@ -46,7 +46,9 @@ public:
void showAtBottom(int x,int y);
void delayHide(int interval = 500);
void cancelHide();
void setContent(QWidget *content);
void resizeWithContent();
void destroyContent();
void move(int x,int y);

View File

@ -0,0 +1,47 @@
#include "closebutton.h"
CloseButton::CloseButton(QWidget *parent) : QLabel(parent)
{
QPixmap iconPixmap(28,28);
iconPixmap.load(ICON_NORMAL_PATH);
this->setPixmap(iconPixmap);
}
void CloseButton::mousePressEvent(QMouseEvent *ev)
{
QPixmap iconPixmap;
iconPixmap.load(ICON_PRESS_PATH);
this->setPixmap(iconPixmap);
emit pressed();
isPressed = true;
}
void CloseButton::mouseReleaseEvent(QMouseEvent *ev)
{
QPixmap iconPixmap;
iconPixmap.load(ICON_NORMAL_PATH);
this->setPixmap(iconPixmap);
emit released();
if (isPressed)
{
emit clicked();
isPressed = false;
}
}
void CloseButton::enterEvent(QEvent *)
{
QPixmap iconPixmap;
iconPixmap.load(ICON_HOVER_PATH);
this->setPixmap(iconPixmap);
emit hovered();
}
void CloseButton::leaveEvent(QEvent *)
{
QPixmap iconPixmap;
iconPixmap.load(ICON_NORMAL_PATH);
this->setPixmap(iconPixmap);
emit exited();
}

View File

@ -0,0 +1,35 @@
#ifndef CLOSEBUTTON_H
#define CLOSEBUTTON_H
#include <QWidget>
#include <QLabel>
class CloseButton : public QLabel
{
Q_OBJECT
public:
explicit CloseButton(QWidget *parent = 0);
void mousePressEvent(QMouseEvent *ev);
void mouseReleaseEvent(QMouseEvent *ev);
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
signals:
void clicked();
void hovered();
void exited();
void pressed();
void released();
public slots:
private:
void setIcon(const QString &path);
private:
bool isPressed = false;
const QString ICON_NORMAL_PATH = "://Resources/images/close_normal.png";
const QString ICON_HOVER_PATH = "://Resources/images/close_hover.png";
const QString ICON_PRESS_PATH = "://Resources/images/close_press.png";
};
#endif // CLOSEBUTTON_H

View File

@ -38,19 +38,24 @@ public:
QPoint globalPos(){return mapToGlobal(QPoint(0,0));}
void showPreview(){
if (!m_previewAR->isHidden())
{
m_previewAR->resizeWithContent();
return;
}
QWidget *tmpContent = getContents();
QSize tmpSize(tmpContent->width() + m_previewAR->getMargin() * 2,
tmpContent->height() + m_previewAR->getMargin() * 2 + m_previewAR->getArrowHeight());
m_previewAR->setMinimumSize(tmpSize);
m_previewAR->resize(tmpSize);
m_previewAR->setArrorDirection(ArrowRectangle::ArrowBottom);
m_previewAR->setContent(tmpContent);
m_previewAR->showAtBottom(globalX() + width() / 2,globalY() - 5);
}
void hidePreview(int interval = 100){
void hidePreview(int interval = 200){
m_previewAR->delayHide(interval);
}
void cancelHide(){m_previewAR->cancelHide();}
void resizePreview(){
m_previewAR->resizeWithContent();
m_previewAR->showAtBottom(globalX() + width() / 2,globalY() - 5);
}
signals:
void dragStart();