Update ArrowRectangle content position

This commit is contained in:
杨万青 2015-07-09 16:58:08 +08:00
parent e9f7f3e068
commit 58ad246ddd
5 changed files with 41 additions and 9 deletions

View File

@ -3,6 +3,7 @@
AppPreviews::AppPreviews(QWidget *parent) : QWidget(parent)
{
m_mainLayout = new QHBoxLayout(this);
m_mainLayout->setMargin(0);
setLayout(m_mainLayout);
resize(Dock::APP_PREVIEW_WIDTH,Dock::APP_PREVIEW_HEIGHT);
}
@ -24,6 +25,7 @@ void AppPreviews::setTitle(const QString &title)
titleLabel->setObjectName("DockAppTitle");
titleLabel->setAlignment(Qt::AlignCenter);
m_mainLayout->addWidget(titleLabel);
resize(100,35);
int textWidth = titleLabel->fontMetrics().boundingRect(titleLabel->text()).width();
resize(textWidth < 80 ? 80 : textWidth,20);
}

View File

@ -100,8 +100,23 @@ void ArrowRectangle::setContent(QWidget *content)
return;
}
m_content = content;
content->setParent(this);
content->move((width() - content->width()) / 2,(height() - content->height()) / 2);
m_content->setParent(this);
switch(arrowDirection)
{
case ArrowLeft:
m_content->move(arrowHeight + m_margin,m_margin);
break;
case ArrowRight:
m_content->move(m_margin,m_margin);
break;
case ArrowTop:
m_content->move(m_margin,m_margin + arrowHeight);
break;
case ArrowBottom:
m_content->move(m_margin,m_margin);
break;
}
}
void ArrowRectangle::destroyContent()
@ -172,7 +187,7 @@ void ArrowRectangle::paintEvent(QPaintEvent *)
strokePen.setColor(strokeColor);
strokePen.setWidth(strokeWidth);
painter.strokePath(border, strokePen);
painter.fillPath(border, QBrush(backgroundColor == "" ? QColor(0,0,0,150) : QColor(backgroundColor)));
painter.fillPath(border, QBrush(backgroundColor == "" ? QColor(0,0,0,200) : QColor(backgroundColor)));
}
void ArrowRectangle::slotHide()
@ -202,6 +217,11 @@ int ArrowRectangle::getArrowWidth()
return this->arrowWidth;
}
int ArrowRectangle::getMargin()
{
return this->m_margin;
}
QString ArrowRectangle::getBackgroundColor()
{
return this->backgroundColor;
@ -239,6 +259,11 @@ void ArrowRectangle::setArrowWidth(int value)
this->arrowWidth = value;
}
void ArrowRectangle::setMargin(int value)
{
this->m_margin = value;
}
void ArrowRectangle::setBackgroundColor(QString value)
{
this->backgroundColor = value;

View File

@ -27,6 +27,7 @@ public:
int getRadius();
int getArrowHeight();
int getArrowWidth();
int getMargin();
QString getBackgroundColor();
void setArrorDirection(ArrowDirection value);
@ -35,6 +36,7 @@ public:
void setRadius(int value);
void setArrowHeight(int value);
void setArrowWidth(int value);
void setMargin(int value);
void setBackgroundColor(QString value);
void show(int x,int y);
@ -58,6 +60,7 @@ private:
int radius = 3;
int arrowHeight = 8;
int arrowWidth = 20;
int m_margin = 5;
QString backgroundColor;
int strokeWidth = 1;

View File

@ -240,8 +240,8 @@ int DockLayout::getContentsWidth()
tmpWidth += appList.at(i)->width();
}
// if (hasSpacingItemInList() && tmpAppMap.firstKey())
// tmpWidth += tmpAppMap.firstKey()->width() + itemSpacing;
if (spacingItemIndex() != -1 && tmpAppMap.firstKey())
tmpWidth += tmpAppMap.firstKey()->width() + itemSpacing;
return tmpWidth;
}

View File

@ -39,13 +39,15 @@ public:
void showPreview(){
QWidget *tmpContent = getContents();
m_previewAR->setMinimumSize(tmpContent->width(),tmpContent->height());
m_previewAR->resize(tmpContent->width(),tmpContent->height());
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->setContent(tmpContent);
m_previewAR->showAtBottom(globalX() + width() / 2,globalY() - 5);
}
void hidePreview(int interval = 300){
void hidePreview(int interval = 100){
m_previewAR->delayHide(interval);
}