diff options
Diffstat (limited to 'tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/topbar.cpp')
-rw-r--r-- | tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/topbar.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/topbar.cpp b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/topbar.cpp index a7a4ad3a3f..9ff6d6d2f1 100644 --- a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/topbar.cpp +++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/topbar.cpp @@ -55,7 +55,7 @@ TopBar::TopBar(QGraphicsView* mainView, QGraphicsWidget* parent) : m_orientation(TopBar::None), m_topBarPixmap(), m_sizesBlue(), m_sizesLime() { setDefaultSizes(); - + m_titleFont = Theme::p()->font(Theme::TitleBar); m_statusFont = Theme::p()->font(Theme::StatusBar); @@ -71,7 +71,7 @@ void TopBar::resizeEvent(QGraphicsSceneResizeEvent* /*event*/) //Check orientation QString topbarName; QSize mainViewSize = m_mainView->size(); - int rotationAngle = static_cast<MainView*>(m_mainView)->rotationAngle(); + int rotationAngle = static_cast<MainView*>(m_mainView)->rotationAngle(); if(rotationAngle == 90 || rotationAngle == 270 ) { int wd = mainViewSize.width(); int ht = mainViewSize.height(); @@ -91,49 +91,49 @@ void TopBar::resizeEvent(QGraphicsSceneResizeEvent* /*event*/) m_orientation = TopBar::Landscape; topbarName = "topbar_horisontal.svg"; } - + //Calculate new size, resize by height, don't make it wider than the screen - QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? + QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? m_sizesBlue : m_sizesLime; - + //Get current size for topbarpixmap - QSize currentSize = !m_topBarPixmap.isNull() && !m_orientationChanged ? + QSize currentSize = !m_topBarPixmap.isNull() && !m_orientationChanged ? m_topBarPixmap.size() : sizes[topbarName]; QSize newSize = !m_orientationChanged ? QSize(currentSize) : sizes[topbarName]; - + //Scale according to aspect ratio newSize.scale(size().toSize(), Qt::KeepAspectRatio); - + //fix width to window widht if previous scaling produced too narrow image if(newSize.width() < size().width()) { newSize.scale(size().toSize(), Qt::KeepAspectRatioByExpanding); } - + //Calculate scaling factor for rest of the graphics scaling qreal scaleFactor = (newSize.width() *1.0) / (currentSize.width() * 1.0); - + //Scale graphics, if the scalefactor applies //This is really heavy since the SVG graphics are read again from the resource if(scaleFactor != 1 || m_topBarPixmap.isNull() ) { m_topBarPixmap = Theme::p()->pixmap(topbarName, newSize ); - m_topBarUserIcon = Theme::p()->pixmap("user_default_icon.svg", + m_topBarUserIcon = Theme::p()->pixmap("user_default_icon.svg", !m_topBarUserIcon.isNull() && !m_orientationChanged ? m_topBarUserIcon.size()* scaleFactor : sizes["user_default_icon.svg"] * scaleFactor); - - m_topBarUserStatus = Theme::p()->pixmap("user_status_online.svg", + + m_topBarUserStatus = Theme::p()->pixmap("user_status_online.svg", !m_topBarUserStatus.isNull() && !m_orientationChanged ? m_topBarUserStatus.size() * scaleFactor : sizes["user_status_online.svg"] * scaleFactor); - - m_topBarStatusBarLeft = Theme::p()->pixmap("status_field_left.svg", + + m_topBarStatusBarLeft = Theme::p()->pixmap("status_field_left.svg", !m_topBarStatusBarLeft.isNull() && !m_orientationChanged ? m_topBarStatusBarLeft.size()* scaleFactor : sizes["status_field_left.svg"] * scaleFactor); - + m_topBarStatusBarRight = Theme::p()->pixmap("status_field_right.svg", !m_topBarStatusBarRight.isNull() && !m_orientationChanged ? m_topBarStatusBarRight.size()* scaleFactor : sizes["status_field_right.svg"] * scaleFactor); - + m_topBarStatusBarMiddle = Theme::p()->pixmap("status_field_middle.svg", !m_topBarStatusBarMiddle.isNull() && !m_orientationChanged ? m_topBarStatusBarMiddle.size() * scaleFactor : QSize(185, sizes["status_field_middle.svg"].height()) * scaleFactor); - + //Update the sizeHint to match the size of the scaled m_topBarPixmap updateGeometry(); - + //Point Update - Positions relative to the Top Bar "Backgroud" size. //TODO: consider some layout instead of calculating relative locations QSize topBarPixmapSize = m_topBarPixmap.size(); @@ -141,40 +141,40 @@ void TopBar::resizeEvent(QGraphicsSceneResizeEvent* /*event*/) QSize topBarUserStatusSize = m_topBarUserStatus.size(); QSize topBarStatusBarLeftSize = m_topBarStatusBarLeft.size(); QSize topBarStatusBarMiddleSize = m_topBarStatusBarMiddle.size(); - + //Location for Title text 5% width, 35% height of the background pixmap - m_topBarTitlePoint = QPoint(topBarPixmapSize.width()* 0.05, + m_topBarTitlePoint = QPoint(topBarPixmapSize.width()* 0.05, topBarPixmapSize.height() * 0.35); - + //User Icon location //Placing 70% of the width and 10% of the height of the top bar background m_topBarUserIconPoint = QPoint((topBarPixmapSize.width() * 0.7), (topBarPixmapSize.height() * 0.1)); - + //If Blue theme is in use - position user status icon on the right side of the user icon if(!m_isLimeTheme) { //Place the status icon on top of the right edge of the user icon, lower it by 35% of the height of the user icon - m_topBarUserStatusPoint = QPoint( ( (m_topBarUserIconPoint.x()+topBarUserIconSize.width() ) - - ( topBarUserStatusSize.width()/2 )), + m_topBarUserStatusPoint = QPoint( ( (m_topBarUserIconPoint.x()+topBarUserIconSize.width() ) - + ( topBarUserStatusSize.width()/2 )), (m_topBarUserIconPoint.y() + (topBarUserIconSize.height() * 0.35 ))); } //If Lime theme is in use - position user status icon on the left side of the user icon else { //Place the status icon on top of the left side of the user icon, lower it by 50% of the height of the user icon //and move left by 5% of the icon - m_topBarUserStatusPoint = QPoint( m_topBarUserIconPoint.x() + ( topBarUserIconSize.width() * 0.05), + m_topBarUserStatusPoint = QPoint( m_topBarUserIconPoint.x() + ( topBarUserIconSize.width() * 0.05), (m_topBarUserIconPoint.y() + (topBarUserIconSize.height() * 0.5 ))); } - + //Status bar //Placing the left side of the status bar 5% of the width, 50% of the height of the top bar background //Set the text baseline 80% of the height of the status bar - m_topBarStatusBarLeftPoint = QPoint( (topBarPixmapSize.width()* 0.05), + m_topBarStatusBarLeftPoint = QPoint( (topBarPixmapSize.width()* 0.05), (topBarPixmapSize.height() * 0.5)); - m_topBarStatusBarMiddlePoint = QPoint( (m_topBarStatusBarLeftPoint.x() + topBarStatusBarLeftSize.width()), + m_topBarStatusBarMiddlePoint = QPoint( (m_topBarStatusBarLeftPoint.x() + topBarStatusBarLeftSize.width()), (m_topBarStatusBarLeftPoint.y())); - m_topBarStatusBarRightPoint = QPoint( (m_topBarStatusBarMiddlePoint.x() + topBarStatusBarMiddleSize.width()), + m_topBarStatusBarRightPoint = QPoint( (m_topBarStatusBarMiddlePoint.x() + topBarStatusBarMiddleSize.width()), (m_topBarStatusBarMiddlePoint.y() ) ); - m_topBarStatusBarTextPoint = QPoint(m_topBarStatusBarMiddlePoint.x(), + m_topBarStatusBarTextPoint = QPoint(m_topBarStatusBarMiddlePoint.x(), m_topBarStatusBarMiddlePoint.y() + (topBarStatusBarMiddleSize.height()*0.8) ); } //if scalefactor } @@ -183,18 +183,18 @@ void TopBar::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, Q { //Topbar background painter->drawPixmap(option->exposedRect, m_topBarPixmap, option->exposedRect); - + //User Icon painter->drawPixmap(m_topBarUserIconPoint, m_topBarUserIcon); - + //User Status painter->drawPixmap(m_topBarUserStatusPoint, m_topBarUserStatus); - + //Status bar painter->drawPixmap(m_topBarStatusBarLeftPoint, m_topBarStatusBarLeft); painter->drawPixmap(m_topBarStatusBarMiddlePoint, m_topBarStatusBarMiddle); painter->drawPixmap(m_topBarStatusBarRightPoint, m_topBarStatusBarRight); - + //Title text painter->save(); painter->setFont(m_titleFont); @@ -210,14 +210,14 @@ void TopBar::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, Q QRectF TopBar::boundingRect() const { - //It's possible that m_topBarPixmap is not allocated yet, + //It's possible that m_topBarPixmap is not allocated yet, //in this case default size is used for setting boundingRect - QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? - m_sizesBlue : m_sizesLime; - - if(!m_topBarPixmap.isNull()) + QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? + m_sizesBlue : m_sizesLime; + + if (!m_topBarPixmap.isNull()) return QRectF(0, 0, m_topBarPixmap.size().width(), m_topBarPixmap.size().height()); - else + else return QRectF(0, 0, sizes["topbar.svg"].width(), sizes["topbar.svg"].height()); } @@ -227,95 +227,95 @@ void TopBar::themeChange() m_statusFont = Theme::p()->font(Theme::StatusBar); //Calculate the scaling factor - QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? + QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? m_sizesBlue : m_sizesLime; - - QString topbarString= m_orientation == TopBar::Portrait ? + + QString topbarString= m_orientation == TopBar::Portrait ? "topbar.svg" : "topbar_horisontal.svg"; - + QSize topBarSize = sizes[topbarString]; QSize newSize = QSize(topBarSize); - + //Scale according to aspect ratio newSize.scale(size().toSize(), Qt::KeepAspectRatio); - + //fix width to window widht if previous scaling produced too narrow image if(newSize.width() < size().width()) { newSize.scale(size().toSize(), Qt::KeepAspectRatioByExpanding); } - + //Calculate scaling factor for rest of the graphics scaling qreal scaleFactor = (newSize.width() *1.0) / (topBarSize.width() * 1.0); //Background m_topBarPixmap = Theme::p()->pixmap(topbarString, sizes[topbarString] * scaleFactor); - + //User Icon m_topBarUserIcon = Theme::p()->pixmap("user_default_icon.svg", sizes["user_default_icon.svg"] * scaleFactor); - + //User Status - m_topBarUserStatus = Theme::p()->pixmap("user_status_online.svg", sizes["user_status_online.svg"] * scaleFactor); - - //Status Bar + m_topBarUserStatus = Theme::p()->pixmap("user_status_online.svg", sizes["user_status_online.svg"] * scaleFactor); + + //Status Bar m_topBarStatusBarLeft = Theme::p()->pixmap("status_field_left.svg", sizes["status_field_left.svg"] * scaleFactor); m_topBarStatusBarRight = Theme::p()->pixmap("status_field_right.svg", sizes["status_field_right.svg"] * scaleFactor); - m_topBarStatusBarMiddle = Theme::p()->pixmap("status_field_middle.svg", + m_topBarStatusBarMiddle = Theme::p()->pixmap("status_field_middle.svg", QSize(185, sizes["status_field_middle.svg"].height())* scaleFactor); - + //Update Drawing points for Top Bar elements, points are relative to the top bar background size QSize topBarPixmapSize = m_topBarPixmap.size(); QSize topBarUserIconSize = m_topBarUserIcon.size(); QSize topBarUserStatusSize = m_topBarUserStatus.size(); QSize topBarStatusBarLeftSize = m_topBarStatusBarLeft.size(); - QSize topBarStatusBarMiddleSize = m_topBarStatusBarMiddle.size(); - + QSize topBarStatusBarMiddleSize = m_topBarStatusBarMiddle.size(); + //Theme Check (Theme::p()->theme() == Theme::Lime) ? m_isLimeTheme = true : m_isLimeTheme = false; - + //User Icon location //Placing 70% of the width and 10% of the height of the top bar background m_topBarUserIconPoint = QPoint((0.7*topBarPixmapSize.width()), (0.1*topBarPixmapSize.height())); - + //If Blue theme is in use - position user status icon on the right side of the user icon if(!m_isLimeTheme) { //Place the status icon on top of the right edge of the user icon, lower it by 35% of the height of the user icon - m_topBarUserStatusPoint = QPoint( ( (m_topBarUserIconPoint.x()+topBarUserIconSize.width() ) - ( topBarUserStatusSize.width()/2 )), + m_topBarUserStatusPoint = QPoint( ( (m_topBarUserIconPoint.x()+topBarUserIconSize.width() ) - ( topBarUserStatusSize.width()/2 )), (m_topBarUserIconPoint.y() + (topBarUserIconSize.height() * 0.35 ))); } //If Lime theme is in use - position user status icon on the left side of the user icon else { //Place the status icon on top of the left side of the user icon, lower it by 50% of the height of the user icon //and move left by 5% of the icon - m_topBarUserStatusPoint = QPoint( m_topBarUserIconPoint.x() + ( topBarUserIconSize.width() * 0.05), + m_topBarUserStatusPoint = QPoint( m_topBarUserIconPoint.x() + ( topBarUserIconSize.width() * 0.05), (m_topBarUserIconPoint.y() + (topBarUserIconSize.height() * 0.5 ))); } - + //Status bar //Placing the left side of the status bar 5% of the width, 50% of the height of the top bar background //Set the text baseline 80% of the height of the status bar - m_topBarStatusBarLeftPoint = QPoint( (topBarPixmapSize.width()* 0.05), + m_topBarStatusBarLeftPoint = QPoint( (topBarPixmapSize.width()* 0.05), (topBarPixmapSize.height() * 0.5)); - m_topBarStatusBarMiddlePoint = QPoint( (m_topBarStatusBarLeftPoint.x() + topBarStatusBarLeftSize.width()), + m_topBarStatusBarMiddlePoint = QPoint( (m_topBarStatusBarLeftPoint.x() + topBarStatusBarLeftSize.width()), (m_topBarStatusBarLeftPoint.y())); - m_topBarStatusBarRightPoint = QPoint( (m_topBarStatusBarMiddlePoint.x() + topBarStatusBarMiddleSize.width()), + m_topBarStatusBarRightPoint = QPoint( (m_topBarStatusBarMiddlePoint.x() + topBarStatusBarMiddleSize.width()), (m_topBarStatusBarMiddlePoint.y() ) ); - m_topBarStatusBarTextPoint = QPoint(m_topBarStatusBarMiddlePoint.x(), + m_topBarStatusBarTextPoint = QPoint(m_topBarStatusBarMiddlePoint.x(), m_topBarStatusBarMiddlePoint.y() + (topBarStatusBarMiddleSize.height()*0.8) ); - + update(); } -QSizeF TopBar::sizeHint(Qt::SizeHint which, - const QSizeF &constraint) const +QSizeF TopBar::sizeHint(Qt::SizeHint which, + const QSizeF &constraint) const { - //It's possible that m_topBarPixmap is not allocated yet, + //It's possible that m_topBarPixmap is not allocated yet, //in this case default size is used for setting size hint - QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? - m_sizesBlue : m_sizesLime; - - int height = !m_topBarPixmap.isNull() ? - m_topBarPixmap.height() : sizes["topbar.svg"].height(); - + QHash<QString, QSize>sizes = (Theme::p()->theme() == Theme::Blue) ? + m_sizesBlue : m_sizesLime; + + int height = !m_topBarPixmap.isNull() ? + m_topBarPixmap.height() : sizes["topbar.svg"].height(); + switch (which) { case Qt::MinimumSize: @@ -330,7 +330,7 @@ QSizeF TopBar::sizeHint(Qt::SizeHint which, } void TopBar::setDefaultSizes() -{ +{ m_sizesBlue["topbar.svg"] = QSize(356,96); m_sizesBlue["topbar_horisontal.svg"] = QSize(636,96); m_sizesBlue["user_default_icon.svg"] = QSize(68,68); @@ -338,7 +338,7 @@ void TopBar::setDefaultSizes() m_sizesBlue["status_field_left.svg"] = QSize(14,24); m_sizesBlue["status_field_right.svg"] = QSize(10,24); m_sizesBlue["status_field_middle.svg"] = QSize(14,24); - + m_sizesLime["topbar.svg"] = QSize(356,96); m_sizesLime["topbar_horisontal.svg"] = QSize(636,96); m_sizesLime["user_default_icon.svg"] = QSize(84,68); |