SpeedCrunch  0.11
/usr/src/RPM/BUILD/speedcrunch-0.11/src/gui/bitfieldwidget.h
Go to the documentation of this file.
00001 // This file is part of the SpeedCrunch project
00002 // Copyright (C) 2014 Sébastien Szymanski <seb.szymanski@gmail.com>
00003 // Copyright (C) 2014 Helder Correia <helder.pereira.correia@gmail.com>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; see the file COPYING.  If not, write to
00017 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018 // Boston, MA 02110-1301, USA.
00019 
00020 #ifndef BITFIELDWIDGET_H
00021 #define BITFIELDWIDGET_H
00022 
00023 #include <QLabel>
00024 #include <QWidget>
00025 
00026 class HNumber;
00027 
00028 class BitWidget : public QLabel {
00029     Q_OBJECT
00030 
00031 public:
00032     explicit BitWidget(int apos, QWidget* parent = 0);
00033 
00034     bool state() const { return m_state; }
00035     void setState(bool state) { m_state = state; update(); }
00036 
00037 signals:
00038     void stateChanged(bool);
00039 
00040 protected:
00041     void mouseReleaseEvent(QMouseEvent*);
00042     void paintEvent(QPaintEvent*);
00043 
00044 private:
00045     enum {
00046         SizePixels = 20,
00047     };
00048 
00049     Q_DISABLE_COPY(BitWidget)
00050 
00051     bool m_state;
00052 };
00053 
00054 class BitFieldWidget : public QWidget {
00055     Q_OBJECT
00056 
00057 public:
00058     explicit BitFieldWidget(QWidget* parent = 0);
00059 
00060 signals:
00061     void bitsChanged(const QString&);
00062 
00063 protected:
00064     virtual void wheelEvent(QWheelEvent *we);
00065 
00066 public slots:
00067     void updateBits(const HNumber&);
00068 
00069 private slots:
00070     void onBitChanged();
00071     void invertBits();
00072     void shiftBitsLeft();
00073     void shiftBitsRight();
00074     void resetBits();
00075 
00076 private:
00077     enum {
00078         NumberOfBits = 64
00079     };
00080 
00081     Q_DISABLE_COPY(BitFieldWidget)
00082 
00083     QList<BitWidget*> m_bitWidgets;
00084 };
00085 
00086 #endif // BITFIELDWIDGET_H