Warning, file /office/calligra/libs/widgets/KoAspectButton.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2005-2007 Thomas Zander <zander@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #include "KoAspectButton.h" 0020 0021 #include <QPixmap> 0022 #include <QPainter> 0023 #include <QMouseEvent> 0024 0025 namespace { 0026 /* XPM -- copyright The Gimp */ 0027 const char * const _chain_broken_24[] = { 0028 /* columns rows colors chars-per-pixel */ 0029 "9 24 10 1", 0030 " c black", 0031 ". c #020204", 0032 "X c #5A5A5C", 0033 "o c gray43", 0034 "O c #8F8F91", 0035 "+ c #9A9A98", 0036 "@ c #B5B5B6", 0037 "# c #D0D0D1", 0038 "$ c #E8E8E9", 0039 "% c None", 0040 /* pixels */ 0041 "%%.....%%", 0042 "%.o##@X.%", 0043 "%.+...$.%", 0044 "%.#.%.#.%", 0045 "%.#.%.#.%", 0046 "%.@.%.#.%", 0047 "%.+...#.%", 0048 "%.O.o.O.%", 0049 "%%..@..%%", 0050 "%%%.#.%%%", 0051 "%%%%%%%%%", 0052 "%%%%%%%%%", 0053 "%%%%%%%%%", 0054 "%%%%%%%%%", 0055 "%%%.#.%%%", 0056 "%%..#..%%", 0057 "%.o.@.O.%", 0058 "%.@...@.%", 0059 "%.@.%.$.%", 0060 "%.@.%.$.%", 0061 "%.@.%.$.%", 0062 "%.#...$.%", 0063 "%.o$#$@.%", 0064 "%%.....%%" 0065 }; 0066 0067 /* XPM -- copyright The Gimp */ 0068 const char * const _chain_24[] = { 0069 /* columns rows colors chars-per-pixel */ 0070 "9 24 10 1", 0071 " c black", 0072 ". c #020204", 0073 "X c #5A5A5C", 0074 "o c gray43", 0075 "O c #8F8F91", 0076 "+ c #9A9A98", 0077 "@ c #B5B5B6", 0078 "# c #D0D0D1", 0079 "$ c #E8E8E9", 0080 "% c None", 0081 /* pixels */ 0082 "%%%%%%%%%", 0083 "%%%%%%%%%", 0084 "%%.....%%", 0085 "%.o##@X.%", 0086 "%.+...$.%", 0087 "%.#.%.#.%", 0088 "%.#.%.#.%", 0089 "%.@.%.#.%", 0090 "%.+...#.%", 0091 "%.O.o.O.%", 0092 "%%..@..%%", 0093 "%%%.#.%%%", 0094 "%%%.#.%%%", 0095 "%%..#..%%", 0096 "%.o.@.O.%", 0097 "%.@...@.%", 0098 "%.@.%.$.%", 0099 "%.@.%.$.%", 0100 "%.@.%.$.%", 0101 "%.#...$.%", 0102 "%.o$#$@.%", 0103 "%%.....%%", 0104 "%%%%%%%%%", 0105 "%%%%%%%%%" 0106 }; 0107 } 0108 0109 class Q_DECL_HIDDEN KoAspectButton::Private 0110 { 0111 public: 0112 Private() 0113 : chain(_chain_24), 0114 brokenChain(_chain_broken_24), 0115 keepAspect(true) 0116 { 0117 } 0118 const QPixmap chain, brokenChain; 0119 bool keepAspect; 0120 }; 0121 0122 KoAspectButton::KoAspectButton(QWidget *parent) 0123 : QAbstractButton(parent), 0124 d( new Private() ) 0125 { 0126 //setPixmap(d->chain); 0127 //setTextInteractionFlags(Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse); 0128 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); 0129 } 0130 0131 KoAspectButton::~KoAspectButton() 0132 { 0133 delete d; 0134 } 0135 0136 void KoAspectButton::mouseReleaseEvent (QMouseEvent *ev) { 0137 if(! isEnabled() || ev->button() != Qt::LeftButton) 0138 return; 0139 setKeepAspectRatio(!d->keepAspect); 0140 } 0141 0142 void KoAspectButton::setKeepAspectRatio(bool on) { 0143 if(d->keepAspect == on) 0144 return; 0145 d->keepAspect = on; 0146 update(); 0147 emit keepAspectRatioChanged(d->keepAspect); 0148 } 0149 0150 void KoAspectButton::paintEvent (QPaintEvent *) { 0151 QPainter painter(this); 0152 painter.drawPixmap(0, (height() - 24) / 2, 9, 24, d->keepAspect ? d->chain : d->brokenChain, 0, 0, 9, 24); 0153 painter.end(); 0154 } 0155 0156 QSize KoAspectButton::sizeHint () const { 0157 return QSize(9, 24); 0158 } 0159 0160 void KoAspectButton::keyReleaseEvent (QKeyEvent *e) { 0161 if(e->text() == " ") { 0162 setKeepAspectRatio(! d->keepAspect); 0163 e->accept(); 0164 } 0165 } 0166 0167 bool KoAspectButton::keepAspectRatio() const 0168 { 0169 return d->keepAspect; 0170 }