00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "linestyleedit.h"
00022 #include "editoritem.h"
00023
00024 #include <QPainter>
00025 #include <QPixmap>
00026 #include <QComboBox>
00027 #include <QLayout>
00028 #include <QVariant>
00029 #include <QHBoxLayout>
00030
00031 using namespace KoProperty;
00032
00034 static const char *nopen[]={
00035 "48 16 1 1",
00036 ". c None",
00037 "................................................",
00038 "................................................",
00039 "................................................",
00040 "................................................",
00041 "................................................",
00042 "................................................",
00043 "................................................",
00044 "................................................",
00045 "................................................",
00046 "................................................",
00047 "................................................",
00048 "................................................",
00049 "................................................",
00050 "................................................",
00051 "................................................",
00052 "................................................"};
00054 static const char *solid[]={
00055 "48 16 2 1",
00056 ". c None",
00057 "# c #000000",
00058 "................................................",
00059 "................................................",
00060 "................................................",
00061 "................................................",
00062 "................................................",
00063 "................................................",
00064 "................................................",
00065 ".###########################################....",
00066 ".###########################################....",
00067 "................................................",
00068 "................................................",
00069 "................................................",
00070 "................................................",
00071 "................................................",
00072 "................................................",
00073 "................................................"};
00075 static const char *dash[]={
00076 "48 16 2 1",
00077 ". c None",
00078 "# c #000000",
00079 "................................................",
00080 "................................................",
00081 "................................................",
00082 "................................................",
00083 "................................................",
00084 "................................................",
00085 "................................................",
00086 ".#########..#########..#########..##########....",
00087 ".#########..#########..#########..##########....",
00088 "................................................",
00089 "................................................",
00090 "................................................",
00091 "................................................",
00092 "................................................",
00093 "................................................",
00094 "................................................"};
00096 static const char *dashdot[]={
00097 "48 16 2 1",
00098 ". c None",
00099 "# c #000000",
00100 "................................................",
00101 "................................................",
00102 "................................................",
00103 "................................................",
00104 "................................................",
00105 "................................................",
00106 "................................................",
00107 ".#########..##..#########..##..#########..##....",
00108 ".#########..##..#########..##..#########..##....",
00109 "................................................",
00110 "................................................",
00111 "................................................",
00112 "................................................",
00113 "................................................",
00114 "................................................",
00115 "................................................"};
00117 static const char *dashdotdot[]={
00118 "48 16 2 1",
00119 ". c None",
00120 "# c #000000",
00121 "................................................",
00122 "................................................",
00123 "................................................",
00124 "................................................",
00125 "................................................",
00126 "................................................",
00127 "................................................",
00128 ".#########..##..##..#########..##..##..#####....",
00129 ".#########..##..##..#########..##..##..#####....",
00130 "................................................",
00131 "................................................",
00132 "................................................",
00133 "................................................",
00134 "................................................",
00135 "................................................",
00136 "................................................"};
00137
00138
00139 LineStyleEdit::LineStyleEdit(Property *property, QWidget *parent)
00140 : Widget(property, parent)
00141 {
00142 QHBoxLayout *l = new QHBoxLayout(this);
00143 l->setMargin(0);
00144 l->setSpacing(0);
00145
00146 m_edit = new QComboBox(this);
00147 m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00148 m_edit->setMinimumHeight(5);
00149 l->addWidget(m_edit);
00150
00151 m_edit->addItem(QIcon(QPixmap(nopen)), "");
00152 m_edit->addItem(QIcon(QPixmap(solid)), "");
00153 m_edit->addItem(QIcon(QPixmap(dash)), "");
00154 m_edit->addItem(QIcon(QPixmap(dashdot)), "");
00155 m_edit->addItem(QIcon(QPixmap(dashdotdot)), "");
00156
00157 setLeavesTheSpaceForRevertButton(true);
00158 setFocusWidget(m_edit);
00159 connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int)));
00160 }
00161
00162 LineStyleEdit::~LineStyleEdit()
00163 {}
00164
00165 QVariant
00166 LineStyleEdit::value() const
00167 {
00168 return m_edit->currentIndex();
00169 }
00170
00171 void
00172 LineStyleEdit::setValue(const QVariant &value, bool emitChange)
00173 {
00174 if (!value.canConvert(QVariant::Int))
00175 return;
00176 if ((value.toInt() > 5) || (value.toInt() < 0))
00177 return;
00178
00179 m_edit->blockSignals(true);
00180 m_edit->setCurrentIndex(value.toInt());
00181 m_edit->blockSignals(false);
00182 if (emitChange)
00183 emit valueChanged(this);
00184 }
00185
00186 void
00187 LineStyleEdit::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value)
00188 {
00189 p->eraseRect(r);
00190
00191 if (!value.canConvert(QVariant::Int))
00192 return;
00193
00194 QPixmap px;
00195 switch (value.toInt()) {
00196 case 0:
00197 px = QPixmap(nopen);
00198 break;
00199 case 1:
00200 px = QPixmap(solid);
00201 break;
00202 case 2:
00203 px = QPixmap(dash);
00204 break;
00205 case 3:
00206 px = QPixmap(dashdot);
00207 break;
00208 case 4:
00209 px = QPixmap(dashdotdot);
00210 break;
00211 default:
00212 return;
00213 }
00214 p->drawPixmap(r.left()+KPROPEDITOR_ITEM_MARGIN, r.top()+(r.height()-px.height())/2, px);
00215 }
00216
00217 void
00218 LineStyleEdit::slotValueChanged(int)
00219 {
00220 emit valueChanged(this);
00221 }
00222
00223 void
00224 LineStyleEdit::setReadOnlyInternal(bool readOnly)
00225 {
00226 setVisibleFlag(!readOnly);
00227 }
00228
00229 #include "linestyleedit.moc"