ctkCheckBoxPixmaps.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 /*=========================================================================
00021 
00022    Program: ParaView
00023    Module:    $RCSfile: pqCheckBoxPixMaps.cxx,v $
00024 
00025    Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
00026    All rights reserved.
00027 
00028    ParaView is a free software; you can redistribute it and/or modify it
00029    under the terms of the ParaView license version 1.2. 
00030 
00031    See License_v1.2.txt for the full ParaView license.
00032    A copy of this license can be obtained by contacting
00033    Kitware Inc.
00034    28 Corporate Drive
00035    Clifton Park, NY 12065
00036    USA
00037 
00038 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00039 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00040 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00041 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
00042 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00043 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00044 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00045 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00046 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00047 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00048 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00049 
00050 ========================================================================*/
00051 
00052 // Qt includes
00053 #include <QWidget>
00054 #include <QPainter>
00055 #include <QPixmap>
00056 #include <QStyle>
00057 #include <QStyleOptionButton>
00058 
00059 // CTK includes
00060 #include "ctkCheckBoxPixmaps.h"
00061 
00062 //-----------------------------------------------------------------------------
00063 ctkCheckBoxPixmaps::ctkCheckBoxPixmaps(QWidget* parentWidget)
00064   : Superclass(parentWidget)
00065 {
00066   Q_ASSERT(parentWidget != 0);
00067 
00068   // Initialize the pixmaps. The following style array should
00069   // correspond to the PixmapStateIndex enum.
00070   const QStyle::State PixmapStyle[] =
00071     {
00072     QStyle::State_On | QStyle::State_Enabled,
00073     QStyle::State_NoChange | QStyle::State_Enabled,
00074     QStyle::State_Off | QStyle::State_Enabled,
00075     QStyle::State_On | QStyle::State_Enabled | QStyle::State_Active,
00076     QStyle::State_NoChange | QStyle::State_Enabled | QStyle::State_Active,
00077     QStyle::State_Off | QStyle::State_Enabled | QStyle::State_Active
00078     };
00079 
00080   QStyleOptionButton option;
00081   QRect r = parentWidget->style()->subElementRect(
00082       QStyle::SE_CheckBoxIndicator, &option, parentWidget);
00083   option.rect = QRect(QPoint(0,0), r.size());
00084   for(int i = 0; i < ctkCheckBoxPixmaps::PixmapCount; i++)
00085     {
00086     this->Pixmaps[i] = QPixmap(r.size());
00087     this->Pixmaps[i].fill(QColor(0, 0, 0, 0));
00088     QPainter painter(&this->Pixmaps[i]);
00089     option.state = PixmapStyle[i];
00090     parentWidget->style()->drawPrimitive(
00091         QStyle::PE_IndicatorCheckBox, &option, &painter, parentWidget);
00092     }
00093 }
00094 
00095 //-----------------------------------------------------------------------------
00096 QPixmap ctkCheckBoxPixmaps::pixmap(Qt::CheckState state, bool active) const
00097 {
00098   int offset = active ? 3 : 0;
00099   switch (state)
00100     {
00101   case Qt::Checked:
00102     return this->Pixmaps[offset + Checked];
00103 
00104   case Qt::Unchecked:
00105     return this->Pixmaps[offset + UnChecked];
00106 
00107   case Qt::PartiallyChecked:
00108     return this->Pixmaps[offset + PartiallyChecked];
00109     }
00110 
00111   return QPixmap();
00112 }
00113 
00114 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1