Commit e36a3c8c authored by Cedric Bellegarde's avatar Cedric Bellegarde
Browse files

Larger button in menubar, keep menubar size the same

parent 9e676aee
......@@ -80,7 +80,7 @@ MenuBar::~MenuBar()
QSize MenuBar::sizeHint() const
{
QSizeF size = m_container->minimumSize();
return QSize(size.width(), size.height());
return QSize(size.width(), size.height() - m_container->contentBottomMargin());
}
void MenuBar::show()
......
......@@ -25,6 +25,13 @@
#include "menubutton.h"
MenuButton::MenuButton(QGraphicsWidget *parent):
Plasma::ToolButton(parent),
m_enterEvent(false),
m_menu(0)
{
}
void MenuButton::setHovered(bool hovered)
{
if (hovered) {
......@@ -34,6 +41,22 @@ void MenuButton::setHovered(bool hovered)
}
}
QSizeF MenuButton::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
{
QSizeF sh = Plasma::ToolButton::sizeHint(which, constraint);
if (which == Qt::MinimumSize || which == Qt::PreferredSize) {
sh.setHeight(nativeWidget()->fontMetrics().height() + bottomMargin());
}
return sh;
}
qreal MenuButton::bottomMargin() const
{
qreal left, right, top, bottom;
getContentsMargins(&left, &right, &top, &bottom);
return bottom;
}
void MenuButton::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
{
m_enterEvent = true;
......
......@@ -33,24 +33,15 @@ class MenuButton : public Plasma::ToolButton
{
Q_OBJECT
public:
MenuButton(QGraphicsWidget *parent):
Plasma::ToolButton(parent),
m_enterEvent(false),
m_menu(0)
{}
MenuButton(QGraphicsWidget *parent);
void setMenu(QMenu *menu) { m_menu = menu; }
QMenu *menu() { return m_menu; }
void setHovered(bool hovered);
QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
{
QSizeF sh = Plasma::ToolButton::sizeHint(which, constraint);
if (which == Qt::MinimumSize || which == Qt::PreferredSize) {
sh.setHeight(nativeWidget()->fontMetrics().height());
}
return sh;
}
QSizeF sizeHint(Qt::SizeHint which, const QSizeF& constraint) const;
qreal bottomMargin() const;
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *);
......
......@@ -23,7 +23,6 @@
DEALINGS IN THE SOFTWARE.
*/
#include "menubutton.h"
#include "menuwidget.h"
#include <QMenu>
......@@ -42,11 +41,10 @@ MenuWidget::MenuWidget(QGraphicsView *view, QMenu *menu) :
m_layout(new QGraphicsLinearLayout(this)),
m_currentButton(0),
m_aMenuIsVisible(false),
m_contentBottomMargin(0),
m_menu(menu)
{
connect(m_mouseTimer, SIGNAL(timeout()), SLOT(slotCheckActiveItem()));
m_layout->setContentsMargins(0, 0, 0, 0);
}
MenuWidget::~MenuWidget()
......@@ -60,11 +58,11 @@ MenuWidget::~MenuWidget()
void MenuWidget::updateLayout()
{
MenuButton* button = 0;
foreach( QAction* action, m_menu->actions() )
{
QMenu *menu = action->menu();
action->setShortcut(QKeySequence());
MenuButton* button;
if( action->isSeparator() || !menu )
continue;
......@@ -77,6 +75,11 @@ void MenuWidget::updateLayout()
m_layout->addItem(button);
m_buttons << button;
}
//Assume all buttons have same margins
if (button) {
m_contentBottomMargin = button->bottomMargin();
}
}
bool MenuWidget::eventFilter(QObject* object, QEvent* event)
......
......@@ -26,12 +26,13 @@
#ifndef MENUWIDGET__H
#define MENUWIDGET__H
#include "menubutton.h"
#include <QGraphicsWidget>
#include <QTimer>
class QGraphicsLinearLayout;
class QGraphicsView;
class MenuButton;
class MenuWidget : public QGraphicsWidget
{
......@@ -63,7 +64,13 @@ public:
*/
void autoOpen() { m_mouseTimer->start(100); }
/**
* Return content bottom margin
*/
qreal contentBottomMargin() { return m_contentBottomMargin; }
void hide();
protected:
/**
* Use to get keyboard events
......@@ -105,6 +112,7 @@ private:
QList<MenuButton*> m_buttons;
MenuButton *m_currentButton;
bool m_aMenuIsVisible;
qreal m_contentBottomMargin;
QMenu *m_menu;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment