qwt_analog_clock.cpp 5.28 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#include "qwt_analog_clock.h"

/*!
  Constructor
  \param parent Parent widget
*/
QwtAnalogClock::QwtAnalogClock(QWidget *parent):
    QwtDial(parent)
{
    initClock();
}

#if QT_VERSION < 0x040000
/*!
  Constructor
  \param parent Parent widget
  \param name Object name
*/
QwtAnalogClock::QwtAnalogClock(QWidget* parent, const char *name):
    QwtDial(parent, name)
{
    initClock();
}
#endif

void QwtAnalogClock::initClock()
{
    setWrapping(true);
    setReadOnly(true);

    setOrigin(270.0);
    setRange(0.0, 60.0 * 60.0 * 12.0); // seconds
    setScale(-1, 5, 60.0 * 60.0);

    setScaleOptions(ScaleTicks | ScaleLabel);
    setScaleTicks(1, 0, 8);
    scaleDraw()->setSpacing(8);

    QColor knobColor =
#if QT_VERSION < 0x040000
        palette().color(QPalette::Active, QColorGroup::Text);
#else
        palette().color(QPalette::Active, QPalette::Text);
#endif
    knobColor = knobColor.dark(120);

    QColor handColor;
    int width;

59 60
    for ( int i = 0; i < NHands; i++ ) {
        if ( i == SecondHand ) {
pixhawk's avatar
pixhawk committed
61 62
            width = 2;
            handColor = knobColor.dark(120);
63
        } else {
pixhawk's avatar
pixhawk committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
            width = 8;
            handColor = knobColor;
        }

        QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
            QwtDialSimpleNeedle::Arrow, true, handColor, knobColor);
        hand->setWidth(width);

        d_hand[i] = NULL;
        setHand((Hand)i, hand);
    }
}

//! Destructor
QwtAnalogClock::~QwtAnalogClock()
{
    for ( int i = 0; i < NHands; i++ )
        delete d_hand[i];
}

84
/*!
pixhawk's avatar
pixhawk committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  Nop method, use setHand instead
  \sa QwtAnalogClock::setHand
*/
void QwtAnalogClock::setNeedle(QwtDialNeedle *)
{
    // no op
    return;
}

/*!
   Set a clockhand
   \param hand Specifies the type of hand
   \param needle Hand
   \sa QwtAnalogClock::hand()
*/
void QwtAnalogClock::setHand(Hand hand,