Commit 8ccfb483 authored by Mathias Soeken's avatar Mathias Soeken

This fixes some clipping bugs with the two labels.

I created a new widget QAutoSizeLabel which automatically resizes itself whenever the text changes.

CCBUG: 142769
CCBUG: 143111

svn path=/trunk/KDE/kdegraphics/kruler/; revision=898218
parent c0a922ca
......@@ -4,7 +4,7 @@ add_subdirectory( pics )
########### next target ###############
set(kruler_SRCS klineal.cpp main.cpp)
set(kruler_SRCS qautosizelabel.cpp klineal.cpp main.cpp)
kde4_add_executable(kruler ${kruler_SRCS})
......
......@@ -39,6 +39,8 @@
#include <KToolInvocation>
#include <KWindowSystem>
#include "qautosizelabel.h"
#define CFG_KEY_BGCOLOR "BgColor"
#define CFG_KEY_SCALE_FONT "ScaleFont"
#define CFG_KEY_LENGTH "Length"
......@@ -47,10 +49,10 @@
#define FULLSCREENID 23
/**
* this is our cursor bitmap:
* a line 48 pixels long with an arrow pointing down
* and a sqare with a one pixel hole at the top (end)
*/
* this is our cursor bitmap:
* a line 48 pixels long with an arrow pointing down
* and a sqare with a one pixel hole at the top (end)
*/
static const uchar cursorBits[] = {
0x38, 0x28, 0x38, 0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
......@@ -109,15 +111,15 @@ KLineal::KLineal( QWidget *parent )
mLongEdgeLen = 400;
}
mLabel = new QLabel( this );
mLabel = new QAutoSizeLabel( this );
mLabel->setGeometry( 0, height() - 12, 32, 12 );
QFont labelFont( KGlobalSettings::generalFont().family(), 10 );
labelFont.setPixelSize( 10 );
mLabel->setFont( labelFont );
mLabel->setWhatsThis( i18n( "This is the current distance measured in pixels." ) );
mColorLabel = new QLabel( this );
mColorLabel = new QAutoSizeLabel( this );
mColorLabel->setAutoFillBackground( true );
mColorLabel->resize( 45, 12 );
//mColorLabel->resize( 45, 12 );
mColorLabel->hide();
QFont colorFont( KGlobalSettings::fixedFont().family(), 10 );
colorFont.setPixelSize( 10 );
......
......@@ -22,7 +22,7 @@
#include <KColorDialog>
class QLabel;
class QAutoSizeLabel;
class KMenu;
class KLineal : public QWidget {
......@@ -57,8 +57,8 @@ private:
bool mDragging;
QPoint mLastClickPos;
QPoint mDragOffset;
QLabel *mLabel;
QLabel *mColorLabel;
QAutoSizeLabel *mLabel;
QAutoSizeLabel *mColorLabel;
int mOrientation;
int mLongEdgeLen;
int mShortEdgeLen;
......
////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2008 Mathias Soeken <msoeken@informatik.uni-bremen.de> //
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU 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 General Public License for more details. //
// //
// You should have received a copy of the GNU 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 "qautosizelabel.h"
#include <QFontMetrics>
QAutoSizeLabel::QAutoSizeLabel( QWidget *parent, Qt::WindowFlags f )
: QLabel( parent, f )
{
resize();
}
QAutoSizeLabel::QAutoSizeLabel( const QString &text, QWidget *parent, Qt::WindowFlags f )
: QLabel( text, parent, f )
{
resize();
}
QAutoSizeLabel::~QAutoSizeLabel()
{
}
void QAutoSizeLabel::setText( const QString &text )
{
QLabel::setText( text );
resize();
}
void QAutoSizeLabel::resize()
{
QFontMetrics fm( font(), this );
QLabel::resize( fm.size( Qt::TextSingleLine, text() ) );
}
#include "qautosizelabel.moc"
////////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2008 Mathias Soeken <msoeken@informatik.uni-bremen.de> //
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU 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 General Public License for more details. //
// //
// You should have received a copy of the GNU 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 QAUTOSIZELABEL_H
#define QAUTOSIZELABEL_H
#include <QLabel>
class QAutoSizeLabel : public QLabel {
Q_OBJECT
public:
explicit QAutoSizeLabel( QWidget *parent = 0, Qt::WindowFlags f = 0 );
explicit QAutoSizeLabel( const QString &text, QWidget *parent = 0, Qt::WindowFlags f = 0 );
virtual ~QAutoSizeLabel();
public Q_SLOTS:
void setText( const QString &text );
private:
void resize();
};
#endif
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