1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Minor circle widget base class cleanup

This commit is contained in:
Daniel Hrabovcak 2015-06-04 12:30:24 -04:00 committed by tux3
parent 715ef0ce65
commit e0b9e81938
17 changed files with 210 additions and 167 deletions

View File

@ -491,7 +491,8 @@ SOURCES += \
src/widget/notificationedgewidget.cpp \
src/widget/circlewidget.cpp \
src/widget/genericchatitemwidget.cpp \
src/widget/friendlistlayout.cpp
src/widget/friendlistlayout.cpp \
src/widget/genericchatitemlayout.cpp
HEADERS += \
src/audio/audio.h \
@ -533,4 +534,4 @@ HEADERS += \
src/widget/circlewidget.h \
src/widget/genericchatitemwidget.h \
src/widget/friendlistlayout.h \
src/widget/sortingboxlayout.h
src/widget/genericchatitemlayout.h

View File

@ -351,6 +351,7 @@ void Core::start()
}
ready = true;
emit started();
// If we created a new profile earlier,
// now that we're ready save it and ONLY THEN broadcast the new ID.
@ -364,6 +365,7 @@ void Core::start()
if (isReady())
GUI::setEnabled(true);
process(); // starts its own timer
}

View File

@ -157,6 +157,9 @@ signals:
void connected();
void disconnected();
void blockingClearContacts();
void started();
void friendRequestReceived(const QString& userId, const QString& message);
void friendMessageReceived(uint32_t friendId, const QString& message, bool isAction);

View File

@ -80,14 +80,12 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
lineFrame->resize(0, 0);
listLayout = new FriendListLayout();
listWidget = new QWidget(this);
listWidget->setLayout(listLayout);
fullLayout->addWidget(listWidget);
setAcceptDrops(true);
listWidget = new QWidget(this);
fullLayout->addWidget(listWidget);
listWidget->setLayout(listLayout);
listWidget->setVisible(false);
onCompactChanged(isCompact());
if (id != -1)
@ -120,8 +118,9 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
if (isNew)
renameCircle();
if (Settings::getInstance().getCircleExpanded(id))
expand();
listWidget->setVisible(Settings::getInstance().getCircleExpanded(id));
//expand();
//Settings::getInstance().setCircleExpanded(id, isExpanded);
}
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
@ -142,15 +141,18 @@ void CircleWidget::toggle()
{
expanded = !expanded;
listWidget->setVisible(expanded);
Settings::getInstance().setCircleExpanded(id, expanded);
if (expanded)
{
//fullLayout->addLayout(listLayout);
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
}
else
{
//fullLayout->removeItem(listLayout);
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
}
Settings::getInstance().setCircleExpanded(id, expanded);
}
void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline)
@ -268,6 +270,20 @@ bool CircleWidget::cycleContacts(FriendWidget *activeChatroomWidget, bool forwar
return false;
}
void CircleWidget::init()
{
qDebug() << "EXPANDED? " << Settings::getInstance().getCircleExpanded(id);
if (Settings::getInstance().getCircleExpanded(id))
expand();
else
{
if (expanded)
{
toggle();
}
}
}
CircleWidget* CircleWidget::getFromID(int id)
{
auto circleIt = circleList.find(id);

View File

@ -48,6 +48,8 @@ public:
bool cycleContacts(bool forward);
bool cycleContacts(FriendWidget* activeChatroomWidget, bool forward);
void init();
static CircleWidget* getFromID(int id);
signals:

View File

@ -40,6 +40,12 @@ FriendListLayout::FriendListLayout()
addLayout(friendOfflineLayout.getLayout());
}
FriendListLayout::FriendListLayout(QWidget *parent)
: QVBoxLayout(parent)
{
FriendListLayout();
}
void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
{
// bug somewhere here.

View File

@ -17,7 +17,7 @@
#include <QBoxLayout>
#include "src/core/corestructs.h"
#include "sortingboxlayout.h"
#include "genericchatitemlayout.h"
#include "friendwidget.h"
class GroupWidget;
@ -30,6 +30,7 @@ class FriendListLayout : public QVBoxLayout
Q_OBJECT
public:
explicit FriendListLayout();
explicit FriendListLayout(QWidget* parent);
void addFriendWidget(FriendWidget* widget, Status s);
int indexOfFriendWidget(FriendWidget* widget, bool online) const;
@ -49,8 +50,8 @@ public:
private:
QLayout* getFriendLayout(Status s);
VSortingBoxLayout<FriendWidget> friendOnlineLayout;
VSortingBoxLayout<FriendWidget> friendOfflineLayout;
GenericChatItemLayout friendOnlineLayout;
GenericChatItemLayout friendOfflineLayout;
};
template <typename WidgetType>

View File

@ -66,6 +66,7 @@ void FriendListWidget::addFriendWidget(FriendWidget *w, Status s, int circleInde
{
CircleWidget::getFromID(circleIndex)->addFriendWidget(w, s);
CircleWidget::getFromID(circleIndex)->show();
//w->setParent(CircleWidget::getFromID(circleIndex));
}
}
@ -75,7 +76,7 @@ void FriendListWidget::addCircleWidget(int id)
circleLayout2.addSortedWidget(circleWidget);
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
//ircleWidget->show(); // Avoid flickering.
circleWidget->show(); // Avoid flickering.
}
void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
@ -99,8 +100,18 @@ void FriendListWidget::removeCircleWidget(CircleWidget *widget)
widget->deleteLater();
}
void FriendListWidget::initCircles()
{
for (int i = 0; i != circleLayout2.getLayout()->count(); ++i)
{
CircleWidget* circleWidget = static_cast<CircleWidget*>(circleLayout2.getLayout()->itemAt(i)->widget());
circleWidget->init();
}
}
void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
{
qDebug() << "searching..................................................";
FriendListLayout::searchLayout<GroupWidget>(searchString, groupLayout.getLayout(), hideGroups);
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
for (int i = 0; i != circleLayout2.getLayout()->count(); ++i)
@ -315,11 +326,13 @@ void FriendListWidget::dropEvent(QDropEvent *event)
void FriendListWidget::moveWidget(FriendWidget *w, Status s, bool add)
{
CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(w->parentWidget());
int circleId = Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId());
CircleWidget *circleWidget = CircleWidget::getFromID(circleId);
if (circleWidget == nullptr || add)
{
Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId(), -1);
if (circleId != -1)
Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId(), -1);
listLayout->addFriendWidget(w, s);
return;
}

View File

@ -27,7 +27,7 @@
#include "src/core/corestructs.h"
#include "src/widget/genericchatroomwidget.h"
#include "sortingboxlayout.h"
#include "genericchatitemlayout.h"
#include "circlewidget.h"
#include "groupwidget.h"
@ -52,6 +52,7 @@ public:
void addCircleWidget(int id);
void addCircleWidget(FriendWidget *widget = nullptr);
void removeCircleWidget(CircleWidget *widget);
void initCircles();
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
@ -79,8 +80,8 @@ private:
bool groupsOnTop;
FriendListLayout* listLayout;
VSortingBoxLayout<CircleWidget> circleLayout2;
VSortingBoxLayout<GroupWidget> groupLayout;
GenericChatItemLayout circleLayout2;
GenericChatItemLayout groupLayout;
};
#endif // FRIENDLISTWIDGET_H

View File

@ -312,6 +312,6 @@ void FriendWidget::setAlias(const QString& _alias)
f->setAlias(alias);
Settings::getInstance().setFriendAlias(f->getToxId(), alias);
Settings::getInstance().savePersonal();
hide();
show();
//hide();
//show();
}

View File

@ -22,6 +22,8 @@
#include "genericchatroomwidget.h"
#include <QDebug>
class QPixmap;
class MaskablePixmapWidget;
@ -52,6 +54,10 @@ protected:
virtual void mousePressEvent(QMouseEvent* ev) final override;
virtual void mouseMoveEvent(QMouseEvent* ev) final override;
void setFriendAlias();
void showEvent(QShowEvent *)
{
qDebug() << "EVENT";
}
public:
int friendId;

View File

@ -0,0 +1,95 @@
/*
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#include "genericchatitemlayout.h"
#include "genericchatitemwidget.h"
#include <QBoxLayout>
#include <cassert>
GenericChatItemLayout::GenericChatItemLayout()
: layout(new QVBoxLayout())
{
}
GenericChatItemLayout::~GenericChatItemLayout()
{
delete layout;
}
void GenericChatItemLayout::addSortedWidget(GenericChatItemWidget* widget, int stretch, Qt::Alignment alignment)
{
int closest = indexOfClosestSortedWidget(widget);
layout->insertWidget(closest, widget, stretch, alignment);
}
int GenericChatItemLayout::indexOfSortedWidget(GenericChatItemWidget* widget) const
{
if (layout->count() == 0)
return -1;
int index = indexOfClosestSortedWidget(widget);
if (index >= layout->count())
return -1;
GenericChatItemWidget* atMid = dynamic_cast<GenericChatItemWidget*>(layout->itemAt(index)->widget());
assert(atMid != nullptr);
if (atMid == widget)
return index;
return -1;
}
bool GenericChatItemLayout::existsSortedWidget(GenericChatItemWidget* widget) const
{
return indexOfSortedWidget(widget) != -1;
}
void GenericChatItemLayout::removeSortedWidget(GenericChatItemWidget* widget)
{
if (layout->isEmpty())
return;
int index = indexOfClosestSortedWidget(widget);
if (layout->itemAt(index) == nullptr)
return;
GenericChatItemWidget* atMid = dynamic_cast<GenericChatItemWidget*>(layout->itemAt(index)->widget());
assert(atMid != nullptr);
if (atMid == widget)
layout->removeWidget(widget);
}
QLayout* GenericChatItemLayout::getLayout() const
{
return layout;
}
int GenericChatItemLayout::indexOfClosestSortedWidget(GenericChatItemWidget* widget) const
{
// Binary search: Deferred test of equality.
int min = 0, max = layout->count(), mid;
while (min < max)
{
mid = (max - min) / 2 + min;
GenericChatItemWidget* atMid = dynamic_cast<GenericChatItemWidget*>(layout->itemAt(mid)->widget());
assert(atMid != nullptr);
if (atMid->getName().localeAwareCompare(widget->getName()) < 0)
min = mid + 1;
else
max = mid;
}
return min;
}

View File

@ -0,0 +1,42 @@
/*
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef GENERICCHATITEMLAYOUT_H
#define GENERICCHATITEMLAYOUT_H
#include <Qt>
class QLayout;
class QVBoxLayout;
class GenericChatItemWidget;
class GenericChatItemLayout
{
public:
GenericChatItemLayout();
~GenericChatItemLayout();
void addSortedWidget(GenericChatItemWidget* widget, int stretch = 0, Qt::Alignment alignment = 0);
int indexOfSortedWidget(GenericChatItemWidget* widget) const;
bool existsSortedWidget(GenericChatItemWidget* widget) const;
void removeSortedWidget(GenericChatItemWidget* widget);
QLayout* getLayout() const;
private:
int indexOfClosestSortedWidget(GenericChatItemWidget* widget) const;
QVBoxLayout* layout;
};
#endif // GENERICCHATITEMLAYOUT_H

View File

@ -43,11 +43,3 @@ QString GenericChatItemWidget::getName() const
{
return nameLabel->fullText();
}
bool GenericChatItemWidget::operator<(const GenericChatItemWidget& other) const
{
int compareValue = getName().localeAwareCompare(other.getName());
//if (compareValue == 0)
// return this < &other; // Consistent ordering.
return compareValue < 0;
}

View File

@ -30,8 +30,6 @@ public:
QString getName() const;
bool operator<(const GenericChatItemWidget& other) const;
Q_PROPERTY(bool compact READ isCompact WRITE setCompact)
protected:

View File

@ -1,135 +0,0 @@
/*
This file is part of qTox, a Qt-based graphical interface for Tox.
This program is libre 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the COPYING file for more details.
*/
#ifndef SORTINGBOXLAYOUT_H
#define SORTINGBOXLAYOUT_H
#include <QBoxLayout>
#include <cassert>
#include <QDebug>
template <typename T, QBoxLayout::Direction Dir>
class SortingBoxLayout
{
public:
static_assert(std::is_base_of<QWidget,T>::value == true, "T must be base of QWidget*.");
SortingBoxLayout();
~SortingBoxLayout();
void addSortedWidget(T* widget);
int indexOfSortedWidget(T* widget) const;
bool existsSortedWidget(T* widget) const;
void removeSortedWidget(T* widget);
QLayout* getLayout() const;
private:
int indexOfClosestSortedWidget(T* widget) const;
QBoxLayout* layout;
};
template <typename T, QBoxLayout::Direction Dir>
SortingBoxLayout<T, Dir>::SortingBoxLayout()
: layout(new QBoxLayout(Dir))
{
}
template <typename T, QBoxLayout::Direction Dir>
SortingBoxLayout<T, Dir>::~SortingBoxLayout()
{
delete layout;
}
template <typename T, QBoxLayout::Direction Dir>
void SortingBoxLayout<T, Dir>::addSortedWidget(T* widget)
{
int closest = indexOfClosestSortedWidget(widget);
layout->insertWidget(closest, widget);
qDebug() << "closest: " << closest;
}
template <typename T, QBoxLayout::Direction Dir>
int SortingBoxLayout<T, Dir>::indexOfSortedWidget(T* widget) const
{
if (layout->count() == 0)
return -1;
int index = indexOfClosestSortedWidget(widget);
if (index >= layout->count())
return -1;
T* atMid = dynamic_cast<T*>(layout->itemAt(index)->widget());
assert(atMid != nullptr);
if (atMid == widget)
return index;
return -1;
}
template <typename T, QBoxLayout::Direction Dir>
bool SortingBoxLayout<T, Dir>::existsSortedWidget(T* widget) const
{
return indexOfSortedWidget(widget) != -1;
}
template <typename T, QBoxLayout::Direction Dir>
void SortingBoxLayout<T, Dir>::removeSortedWidget(T* widget)
{
if (layout->isEmpty())
return;
int index = indexOfClosestSortedWidget(widget);
if (layout->itemAt(index) == nullptr)
return;
T* atMid = dynamic_cast<T*>(layout->itemAt(index)->widget());
assert(atMid != nullptr);
if (atMid == widget)
layout->removeWidget(widget);
}
template <typename T, QBoxLayout::Direction Dir>
QLayout* SortingBoxLayout<T, Dir>::getLayout() const
{
return layout;
}
template <typename T, QBoxLayout::Direction Dir>
int SortingBoxLayout<T, Dir>::indexOfClosestSortedWidget(T* widget) const
{
qDebug() << "USING 6";
// Binary search: Deferred test of equality.
int min = 0, max = layout->count(), mid;
while (min < max)
{
mid = (max - min) / 2 + min;
T* atMid = dynamic_cast<T*>(layout->itemAt(mid)->widget());
assert(atMid != nullptr);
if (*atMid < *widget)
min = mid + 1;
else
max = mid;
}
return min;
}
template <typename T>
using VSortingBoxLayout = SortingBoxLayout<T, QBoxLayout::TopToBottom>;
#endif // SORTINGBOXLAYOUT_H

View File

@ -237,7 +237,6 @@ void Widget::init()
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
{
qDebug() << "HELELEL";
contactListWidget->addCircleWidget(i);
}
}
@ -583,6 +582,7 @@ void Widget::reloadHistory()
void Widget::addFriend(int friendId, const QString &userId)
{
qDebug() << "ADDING FRIEND ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;";
ToxId userToxId = ToxId(userId);
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
contactListWidget->addFriendWidget(newfriend->getFriendWidget(),Status::Offline,Settings::getInstance().getFriendCircleIndex(newfriend->getToxId()));