Skip to content

Commit

Permalink
User defined frames in AbstractProperties windows. Not complete yet
Browse files Browse the repository at this point in the history
Still need to add a remove frame button.
  • Loading branch information
arntanguy committed Jun 26, 2009
1 parent 4908b21 commit 5706e44
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
41 changes: 29 additions & 12 deletions items/AbstractProperties.cpp
Expand Up @@ -18,6 +18,7 @@
#include "ui_AbstractProperties.h"
#include "frames/FrameFactory.h"
#include <QGraphicsSceneMouseEvent>
#include <QFileDialog>
#include <QListWidgetItem>
#include <QPainter>
#include <QPixmapCache>
Expand Down Expand Up @@ -156,18 +157,7 @@ AbstractProperties::AbstractProperties(AbstractContent * content, QGraphicsItem
#endif
m_commonUi->setupUi(widget);

// add frame items to the listview
foreach (quint32 frameClass, FrameFactory::classes()) {
// make icon from frame preview
Frame * frame = FrameFactory::createFrame(frameClass);
QIcon icon(frame->preview(48, 48));
delete frame;

// add the item to the list (and attach it the class)
QListWidgetItem * item = new QListWidgetItem(icon, QString(), m_commonUi->listWidget);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
item->setData(Qt::UserRole, frameClass);
}
populateFrameList();

// select the frame
quint32 frameClass = m_content->frameClass();
Expand All @@ -193,6 +183,7 @@ AbstractProperties::AbstractProperties(AbstractContent * content, QGraphicsItem
connect(m_commonUi->del, SIGNAL(clicked()), m_content, SIGNAL(deleteItem()), Qt::QueuedConnection);
// autoconnection doesn't work because we don't do ->setupUi(this), so here we connect manually
connect(m_commonUi->applyLooks, SIGNAL(clicked()), this, SLOT(on_applyLooks_clicked()));
connect(m_commonUi->newFrame, SIGNAL(clicked()), this, SLOT(on_newFrame_clicked()));
connect(m_commonUi->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(on_listWidget_itemSelectionChanged()));
connect(m_commonUi->reflection, SIGNAL(toggled(bool)), this, SLOT(on_reflection_toggled(bool)));

Expand All @@ -216,6 +207,22 @@ AbstractContent * AbstractProperties::content() const
return m_content;
}

void AbstractProperties::populateFrameList()
{
m_commonUi->listWidget->clear();
// add frame items to the listview
foreach (quint32 frameClass, FrameFactory::classes()) {
// make icon from frame preview
Frame * frame = FrameFactory::createFrame(frameClass);
QIcon icon(frame->preview(48, 48));
delete frame;

// add the item to the list (and attach it the class)
QListWidgetItem * item = new QListWidgetItem(icon, QString(), m_commonUi->listWidget);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
item->setData(Qt::UserRole, frameClass);
}
}
void AbstractProperties::keepInBoundaries(const QRect & rect)
{
QRect r = mapToScene(boundingRect()).boundingRect().toRect();
Expand Down Expand Up @@ -326,6 +333,16 @@ void AbstractProperties::addTab(QWidget * widget, const QString & label, bool fr
m_commonUi->tab->parentWidget()->adjustSize();
}

void AbstractProperties::on_newFrame_clicked()
{
QStringList framesPath = QFileDialog::getOpenFileNames(0, tr("Choose frame images"), QString(), tr("Images (*.svg)"));
if (!framesPath.isEmpty())
foreach (QString frame, framesPath) {
FrameFactory::addSvgFrame(frame);
}
populateFrameList();
}

void AbstractProperties::on_applyLooks_clicked()
{
emit applyLook(m_content->frameClass(), m_content->mirrorEnabled(), true);
Expand Down
4 changes: 4 additions & 0 deletions items/AbstractProperties.h
Expand Up @@ -42,6 +42,7 @@ class AbstractProperties : public QGraphicsProxyWidget {
void closing();
void closed();
void applyLook(quint32 frameClass, bool mirrored, bool allContents);
void createNewFrame(QStringList);

protected:
// used by subclasses
Expand All @@ -63,7 +64,10 @@ class AbstractProperties : public QGraphicsProxyWidget {
bool m_aniDirection;
QBasicTimer m_aniTimer;

void populateFrameList();

private Q_SLOTS:
void on_newFrame_clicked();
void on_applyLooks_clicked();
void on_listWidget_itemSelectionChanged();
void on_reflection_toggled(bool checked);
Expand Down
12 changes: 11 additions & 1 deletion items/AbstractProperties.ui
Expand Up @@ -228,6 +228,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newFrame">
<property name="text">
<string>new frame</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="applyLooks">
<property name="text">
Expand Down Expand Up @@ -271,7 +281,7 @@
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::NoDragDrop</enum>
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down

0 comments on commit 5706e44

Please sign in to comment.