Commit fbb97848 authored by Stefan Majewsky's avatar Stefan Majewsky

Fix layout issues in TriggerListView.

svn path=/trunk/KDE/kdegames/palapeli/; revision=1117448
parent ed31f12a
......@@ -2,6 +2,7 @@
set_directory_properties(PROPERTIES COMPILE_DEFINITIONS USE_LOCAL_LIBPALA)
set(palapeli_SRCS
config/elidinglabel.cpp
config/mouseinputbutton.cpp
config/triggerconfigwidget.cpp
config/triggerlistview.cpp
......
/***************************************************************************
* Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/
#include "elidinglabel.h"
#include <QFontMetrics>
#include <QLabel>
Palapeli::ElidingLabel::ElidingLabel(QWidget* parent)
: QLabel(parent)
{
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
QString Palapeli::ElidingLabel::fullText() const
{
return m_fullText;
}
QSize Palapeli::ElidingLabel::minimumSizeHint() const
{
Palapeli::ElidingLabel* mutableThis = const_cast<Palapeli::ElidingLabel*>(this);
//calculate size hint from full text
const QString elidedText = text();
mutableThis->setText(m_fullText);
const QSize result = QLabel::minimumSizeHint();
mutableThis->setText(elidedText);
//eliding is enabled by decreasing the minimum size hint
return QSize(result.width() / 3, result.height());
}
QSize Palapeli::ElidingLabel::sizeHint() const
{
Palapeli::ElidingLabel* mutableThis = const_cast<Palapeli::ElidingLabel*>(this);
//calculate size hint from full text
const QString elidedText = text();
mutableThis->setText(m_fullText);
const QSize result = QLabel::sizeHint();
mutableThis->setText(elidedText);
//eliding is enabled by decreasing the size hint
return QSize(result.width() / 3, result.height());
}
void Palapeli::ElidingLabel::setFullText(const QString& text)
{
m_fullText = text;
resizeEvent(0); //change text in label
}
void Palapeli::ElidingLabel::resizeEvent(QResizeEvent* event)
{
if (event)
QLabel::resizeEvent(event);
//display elided text
const QFontMetrics fm = fontMetrics();
const QString text = fm.elidedText(m_fullText, Qt::ElideRight, width());
setText(text);
//enable tooltip with fullText if necessary
setToolTip((text == m_fullText) ? QString() : m_fullText);
}
/***************************************************************************
* Copyright 2010 Stefan Majewsky <majewsky@gmx.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/
#ifndef PALAPELI_ELIDINGLABEL_H
#define PALAPELI_ELIDINGLABEL_H
#include <QLabel>
namespace Palapeli
{
class ElidingLabel : public QLabel
{
public:
ElidingLabel(QWidget* parent = 0);
virtual QSize minimumSizeHint() const;
virtual QSize sizeHint() const;
QString fullText() const;
void setFullText(const QString& text);
protected:
virtual void resizeEvent(QResizeEvent* event);
private:
QString m_fullText;
};
}
#endif // PALAPELI_ELIDINGLABEL_H
......@@ -39,11 +39,11 @@ namespace Palapeli
virtual void enterEvent(QEvent*)
{
//TODO: respect global icon size configuration
setPixmap(m_icon.pixmap(22, QIcon::Active));
setPixmap(m_icon.pixmap(16, QIcon::Active));
}
virtual void leaveEvent(QEvent*)
{
setPixmap(m_icon.pixmap(22, QIcon::Normal));
setPixmap(m_icon.pixmap(16, QIcon::Normal));
}
virtual void mousePressEvent(QMouseEvent* event)
{
......
......@@ -17,6 +17,7 @@
***************************************************************************/
#include "triggerlistview.h"
#include "elidinglabel.h"
#include "mouseinputbutton.h"
#include "../engine/interactor.h"
......@@ -63,7 +64,7 @@ namespace Palapeli
TriggerListDelegateWidget(QWidget* parent = 0) : QWidget(parent)
{
m_iconLabel = new QLabel(this);
m_nameLabel = new QLabel(this);
m_nameLabel = new Palapeli::ElidingLabel(this);
m_inputButton = new Palapeli::MouseInputButton(this);
connect(m_inputButton, SIGNAL(triggerChanged(const Palapeli::InteractorTrigger&)), SIGNAL(triggerChanged(const Palapeli::InteractorTrigger&)));
//construct layout
......@@ -72,7 +73,6 @@ namespace Palapeli
layout->addWidget(m_iconLabel);
m_iconLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
layout->addWidget(m_nameLabel);
m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->addWidget(m_inputButton);
m_inputButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
}
......@@ -83,7 +83,7 @@ namespace Palapeli
}
void setText(const QString& text)
{
m_nameLabel->setText(text);
m_nameLabel->setFullText(text);
}
void setTrigger(const Palapeli::InteractorTrigger& trigger)
{
......@@ -93,7 +93,7 @@ namespace Palapeli
void triggerChanged(const Palapeli::InteractorTrigger& newTrigger);
private:
QLabel* m_iconLabel;
QLabel* m_nameLabel;
Palapeli::ElidingLabel* m_nameLabel;
Palapeli::MouseInputButton* m_inputButton;
};
......
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