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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "xml.h"
#include "icon.h"
#include "property.h"
namespace Ms {
//---------------------------------------------------------
// write
//---------------------------------------------------------
void Icon::write(XmlWriter& xml) const
{
xml.stag(this);
xml.tag("subtype", int(_iconType));
if (!_action.isEmpty())
xml.tag("action", _action.data());
xml.etag();
}
//---------------------------------------------------------
// read
//---------------------------------------------------------
void Icon::read(XmlReader& e)
{
while (e.readNextStartElement()) {
const QStringRef& tag(e.name());
if (tag == "action")
_action = e.readElementText().toLocal8Bit();
else if (tag == "subtype")
_iconType = IconType(e.readInt());
else
e.unknown();
}
}
//---------------------------------------------------------
// layout
//---------------------------------------------------------
void Icon::layout()
{
setbbox(QRectF(0, 0, _extent, _extent));
}
//---------------------------------------------------------
// draw
//---------------------------------------------------------
void Icon::draw(QPainter* p) const
{
QPixmap pm(_icon.pixmap(_extent, QIcon::Normal, QIcon::On));
p->drawPixmap(0, 0, pm);
}
//---------------------------------------------------------
// Icon::getProperty
//---------------------------------------------------------
QVariant Icon::getProperty(Pid pid) const
{
switch (pid) {
case Pid::ACTION:
return action();
default:
break;
}
return Element::getProperty(pid);
}
//---------------------------------------------------------
// Icon::setProperty
//---------------------------------------------------------
bool Icon::setProperty(Pid pid, const QVariant& v)
{
switch (pid) {
case Pid::ACTION:
_action = v.toString().toLatin1();
triggerLayout();
break;
default:
return Element::setProperty(pid, v);
}
return true;
}
}
|