OTHER: Replaced SmallNumberDisplay

This commit is contained in:
Thomas Frauendorfer 2008-07-11 03:41:45 +02:00
parent a89be5dd9b
commit 058e2d0987
10 changed files with 153 additions and 126 deletions

View file

@ -0,0 +1,80 @@
/**
* This file is a part of Promoe, an XMMS2 Client.
*
* Copyright (C) 2005-2008 XMMS2 Team
*
* 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.
*/
#include "pixmapnumberdisplay.h"
#include "math.h"
#include <QPainter>
PixmapNumberDisplay::PixmapNumberDisplay (QWidget *parent) : QWidget (parent)
{
}
void
PixmapNumberDisplay::setPixmaps (PixmapMap numbers)
{
m_numbers = numbers;
update ();
}
void
PixmapNumberDisplay::setValue (int value)
{
if (m_value == value)
return;
m_value = value;
update ();
}
void
PixmapNumberDisplay::setDigits (unsigned int digits)
{
if (m_digits == digits)
return;
m_digits = digits;
update ();
}
int
PixmapNumberDisplay::getDigitAtPos (unsigned int position) {
if (m_value == 0) {
if (position == 1)
return 0;
else
return -1;
}
if ( m_value / (unsigned int) pow (10, position - 1) == 0)
return -1;
return (unsigned int) (m_value / pow (10, position - 1)) % 10;
}
void
PixmapNumberDisplay::paintEvent (QPaintEvent *event)
{
QPainter paint;
paint.begin (this);
for (unsigned int i = 0; i < m_digits; i++) {
paint.drawPixmap (i*5, 0,
m_numbers[getDigitAtPos (m_digits - i)]);
}
paint.end ();
}

View file

@ -0,0 +1,49 @@
/**
* This file is a part of Promoe, an XMMS2 Client.
*
* Copyright (C) 2005-2008 XMMS2 Team
*
* 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.
*/
#ifndef __PIXMAPNUMBERDISPLAY_H__
#define __PIXMAPNUMBERDISPLAY_H__
#include <QWidget>
#include <QMap>
class QPaintEvent;
class Skin;
typedef QMap<int, QPixmap> PixmapMap;
class PixmapNumberDisplay : public QWidget
{
Q_OBJECT;
public:
PixmapNumberDisplay (QWidget *parent);
~PixmapNumberDisplay () { };
void setValue (int value);
void setDigits (unsigned int digits);
void setPixmaps (PixmapMap numbers);
private:
int m_value;
unsigned int m_digits;
PixmapMap m_numbers;
int getDigitAtPos (unsigned int position);
void paintEvent (QPaintEvent *event);
};
#endif

View file

@ -1,7 +1,9 @@
HEADERS += pixmapbutton.h \
pixmapnumberdisplay.h \
pixmapslider.h
SOURCES += pixmapbutton.cpp \
pixmapnumberdisplay.cpp \
pixmapslider.cpp
INCLUDEPATH += $$PWD