No longer honours following status in JSON, instead relies solely on following list.
[larjonas-pumpa.git] / src / shortobjectwidget.cpp
blobb547ece1455118845926d571d9b42a69f63d4dde
1 /*
2 Copyright 2013-2015 Mats Sjöberg
4 This file is part of the Pumpa programme.
6 Pumpa is free software: you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 Pumpa is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pumpa. If not, see <http://www.gnu.org/licenses/>.
20 #include "shortobjectwidget.h"
21 #include "util.h"
23 #include <QVBoxLayout>
25 //------------------------------------------------------------------------------
27 ShortObjectWidget::ShortObjectWidget(QASObject* obj, QWidget* parent) :
28 QFrame(parent),
29 m_object(NULL),
30 m_actor(NULL)
32 #ifdef DEBUG_WIDGETS
33 qDebug() << "Creating ShortObjectWidget";
34 #endif
35 m_textLabel = new RichTextLabel(this, true);
37 m_actorWidget = new ActorWidget(NULL, this, true);
38 connect(m_actorWidget, SIGNAL(follow(QString, bool)),
39 this, SIGNAL(follow(QString, bool)));
40 connect(m_actorWidget, SIGNAL(moreClicked()), this, SIGNAL(moreClicked()));
42 m_moreButton = new TextToolButton("+", this);
43 connect(m_moreButton, SIGNAL(clicked()), this, SIGNAL(moreClicked()));
45 QHBoxLayout* acrossLayout = new QHBoxLayout;
46 // acrossLayout->setSpacing(10);
47 acrossLayout->setContentsMargins(0, 0, 0, 0);
48 acrossLayout->addWidget(m_actorWidget, 0, Qt::AlignVCenter);
49 acrossLayout->addWidget(m_textLabel, 0, Qt::AlignVCenter);
50 acrossLayout->addWidget(m_moreButton, 0, Qt::AlignVCenter);
52 changeObject(obj);
54 setLayout(acrossLayout);
57 //------------------------------------------------------------------------------
59 ShortObjectWidget::~ShortObjectWidget() {
60 #ifdef DEBUG_WIDGETS
61 qDebug() << "Deleting ShortObjectWidget" << m_object->id();
62 #endif
65 //------------------------------------------------------------------------------
67 void ShortObjectWidget::changeObject(QASAbstractObject* obj) {
68 if (m_object != NULL)
69 disconnect(m_object, SIGNAL(changed()), this, SLOT(onChanged()));
71 m_object = qobject_cast<QASObject*>(obj);
72 if (!m_object)
73 return;
75 connect(m_object, SIGNAL(changed()), this, SLOT(onChanged()));
77 if (m_actor != NULL)
78 disconnect(m_actor, SIGNAL(changed()),
79 m_actorWidget, SLOT(updateMenu()));
81 QASActor* m_actor = m_object->asActor();
82 if (!m_actor) {
83 m_actor = m_object->author();
84 if (m_actor)
85 connect(m_actor, SIGNAL(changed()),
86 m_actorWidget, SLOT(updateMenu()));
88 m_actorWidget->setActor(m_actor);
90 static QSet<QString> expandableTypes;
91 if (expandableTypes.isEmpty())
92 expandableTypes << "person" << "note" << "comment" << "image" << "video"
93 << "audio";
95 m_moreButton->setVisible(expandableTypes.contains(m_object->type())
96 && !m_object->isDeleted());
98 updateText();
101 //------------------------------------------------------------------------------
103 void ShortObjectWidget::updateText() {
104 if (!m_object)
105 return;
107 QString content = m_object->excerpt();
109 QString text;
110 QASActor* author = m_object->author();
111 if (author && !author->displayName().isEmpty())
112 text = author->displayName();
113 if (!content.isEmpty())
114 text += (text.isEmpty() ? "" : ": ") + content;
116 m_textLabel->setText(text);
119 //------------------------------------------------------------------------------
121 void ShortObjectWidget::onChanged() {
122 updateText();
123 m_actorWidget->updateMenu();
126 //------------------------------------------------------------------------------