File: WordcloudAppliance.cpp

package info (click to toggle)
fotowall 0.9-8
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,280 kB
  • sloc: cpp: 23,275; makefile: 51; sh: 25
file content (124 lines) | stat: -rw-r--r-- 3,694 bytes parent folder | download | duplicates (3)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/***************************************************************************
 *                                                                         *
 *   This file is part of the Fotowall project,                            *
 *       http://www.enricoros.com/opensource/fotowall                      *
 *                                                                         *
 *   Copyright (C) 2009 by Enrico Ros <enrico.ros@gmail.com>               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "WordcloudAppliance.h"

#include "Wordcloud/WordItem.h"
#include "WordcloudSidebar.h"

#include <QPushButton>

WordcloudScene::WordcloudScene(Wordcloud::Cloud * cloud, QObject * parent)
  : AbstractScene(parent)
  , m_cloud(cloud)
{
    m_cloud->setScene(this);
    foreach (QGraphicsItem * item, items()) {
        Wordcloud::WordItem * word = dynamic_cast<Wordcloud::WordItem *>(item);
        if (word)
            connect(word, SIGNAL(moved()), this, SLOT(slotWordMoved()), Qt::QueuedConnection);
    }
}

void WordcloudScene::resize(const QSize & size)
{
    QRectF itemsRect = itemsBoundingRect();
    QSize newSize = itemsRect.size().toSize().expandedTo(size);

    AbstractScene::resize(newSize);

    QPointF delta = sceneCenter() - itemsRect.center();
    if (!delta.isNull()) {
        foreach (QGraphicsItem * item, items())
            item->setPos(item->pos() + delta);
    }
}

void WordcloudScene::slotWordMoved()
{
    adjustSceneSize();
}

WordcloudAppliance::WordcloudAppliance(Wordcloud::Cloud * extCloud, QObject * parent)
  : QObject(parent)
  , m_extCloud(extCloud)
  , m_scene(new WordcloudScene(extCloud))
  , ui(new Ui::WordcloudApplianceElements)
  , m_dummyWidget(new QWidget)
  , m_sidebar(0)
{
    // init UI
    ui->setupUi(m_dummyWidget);

    // create and connect the sidebar
    m_sidebar = new WordcloudSidebar;
    connect(m_sidebar->regenButton, SIGNAL(clicked()), this, SLOT(slotRegenCloud()));
    connect(m_sidebar->randomButton, SIGNAL(clicked()), this, SLOT(slotRandomizeCloud()));

    // configure the appliance
    sceneSet(m_scene);
    sidebarSetWidget(m_sidebar);
}

WordcloudAppliance::~WordcloudAppliance()
{
    if (m_extCloud) {
        qWarning("WordcloudAppliance::~WordcloudAppliance: cloud's still here.. take it!");
        m_extCloud->setScene(0);
    }
    delete m_sidebar;
    delete m_scene;
    delete m_dummyWidget;
    delete ui;
}

Wordcloud::Cloud * WordcloudAppliance::takeCloud()
{
    Wordcloud::Cloud * cloud = m_extCloud;
    m_extCloud = 0;
    cloud->setScene(0);
    sceneClear();
    return cloud;
}

Wordcloud::Cloud * WordcloudAppliance::cloud() const
{
    return m_extCloud;
}

bool WordcloudAppliance::appliancePendingChanges() const
{
    // ###
    return true;
}

bool WordcloudAppliance::applianceSave(const QString &__filePath)
{
    if (__filePath.isEmpty()) {
        // ###
        qWarning("WordcloudAppliance::saveToFile: not implemented");
    }
    qWarning("WordcloudAppliance::saveToFile: not implemented");
    return true;
}

void WordcloudAppliance::slotRegenCloud()
{
    m_extCloud->regenCloud();
}

void WordcloudAppliance::slotRandomizeCloud()
{
    m_extCloud->randomCloud();
}