random shit changes

This commit is contained in:
Rasmus Karlsson
2017-06-10 22:48:28 +02:00
parent 6898f9c2db
commit 1472471ddb
5 changed files with 37 additions and 30 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ void ChatWidget::setChannelName(const QString &name)
printf("Set channel name xD %s\n", qPrintable(name)); printf("Set channel name xD %s\n", qPrintable(name));
if (channelName.isEmpty()) { if (channelName.isEmpty()) {
_channel = NULL; _channel = nullptr;
} else { } else {
_channel = ChannelManager::getInstance().addChannel(channelName); _channel = ChannelManager::getInstance().addChannel(channelName);
printf("Created channel FeelsGoodMan %p\n", _channel.get()); printf("Created channel FeelsGoodMan %p\n", _channel.get());
+11 -1
View File
@@ -18,12 +18,22 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
// Each ChatWidget consists of three sub-elements that handle their own part of the chat widget:
// ChatWidgetHeader
// - Responsible for rendering which channel the ChatWidget is in, and the menu in the top-left of
// the chat widget
// ChatWidgetView
// - Responsible for rendering all chat messages, and the scrollbar
// ChatWidgetInput
// - Responsible for rendering and handling user text input
//
// Each sub-element has a reference to the parent Chat Widget
class ChatWidget : public QWidget class ChatWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
ChatWidget(QWidget *parent = 0); ChatWidget(QWidget *parent = nullptr);
~ChatWidget(); ~ChatWidget();
SharedChannel getChannel() const; SharedChannel getChannel() const;
+14 -15
View File
@@ -11,9 +11,9 @@
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {
ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent) ChatWidgetHeader::ChatWidgetHeader(ChatWidget *_chatWidget)
: QWidget() : QWidget(_chatWidget)
, _chatWidget(parent) , chatWidget(_chatWidget)
, _dragStart() , _dragStart()
, _dragging(false) , _dragging(false)
, _leftLabel() , _leftLabel()
@@ -82,7 +82,7 @@ void ChatWidgetHeader::updateColors()
void ChatWidgetHeader::updateChannelText() void ChatWidgetHeader::updateChannelText()
{ {
const QString &c = _chatWidget->getChannelName(); const QString &c = this->chatWidget->getChannelName();
_middleLabel.setText(c.isEmpty() ? "<no channel>" : c); _middleLabel.setText(c.isEmpty() ? "<no channel>" : c);
} }
@@ -108,18 +108,17 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
if (_dragging) { if (_dragging) {
if (std::abs(_dragStart.x() - event->pos().x()) > 12 || if (std::abs(_dragStart.x() - event->pos().x()) > 12 ||
std::abs(_dragStart.y() - event->pos().y()) > 12) { std::abs(_dragStart.y() - event->pos().y()) > 12) {
auto chatWidget = _chatWidget; auto page = static_cast<NotebookPage *>(this->chatWidget->parentWidget());
auto page = static_cast<NotebookPage *>(chatWidget->parentWidget());
if (page != NULL) { if (page != nullptr) {
NotebookPage::isDraggingSplit = true; NotebookPage::isDraggingSplit = true;
NotebookPage::draggingSplit = chatWidget; NotebookPage::draggingSplit = this->chatWidget;
auto originalLocation = page->removeFromLayout(chatWidget); auto originalLocation = page->removeFromLayout(this->chatWidget);
// page->update(); // page->update();
QDrag *drag = new QDrag(chatWidget); QDrag *drag = new QDrag(this->chatWidget);
QMimeData *mimeData = new QMimeData; QMimeData *mimeData = new QMimeData;
mimeData->setData("chatterino/split", "xD"); mimeData->setData("chatterino/split", "xD");
@@ -129,7 +128,7 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
Qt::DropAction dropAction = drag->exec(Qt::MoveAction); Qt::DropAction dropAction = drag->exec(Qt::MoveAction);
if (dropAction == Qt::IgnoreAction) { if (dropAction == Qt::IgnoreAction) {
page->addToLayout(chatWidget, originalLocation); page->addToLayout(this->chatWidget, originalLocation);
} }
NotebookPage::isDraggingSplit = false; NotebookPage::isDraggingSplit = false;
@@ -141,7 +140,7 @@ void ChatWidgetHeader::mouseMoveEvent(QMouseEvent *event)
void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event) void ChatWidgetHeader::mouseDoubleClickEvent(QMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
_chatWidget->showChangeChannelPopup(); this->chatWidget->showChangeChannelPopup();
} }
} }
@@ -157,7 +156,7 @@ void ChatWidgetHeader::rightButtonClicked()
void ChatWidgetHeader::menuAddSplit() void ChatWidgetHeader::menuAddSplit()
{ {
auto page = static_cast<NotebookPage *>(_chatWidget->parentWidget()); auto page = static_cast<NotebookPage *>(this->chatWidget->parentWidget());
page->addChat(); page->addChat();
} }
void ChatWidgetHeader::menuCloseSplit() void ChatWidgetHeader::menuCloseSplit()
@@ -170,12 +169,12 @@ void ChatWidgetHeader::menuMoveSplit()
void ChatWidgetHeader::menuPopup() void ChatWidgetHeader::menuPopup()
{ {
auto widget = new ChatWidget(); auto widget = new ChatWidget();
widget->setChannelName(_chatWidget->getChannelName()); widget->setChannelName(this->chatWidget->getChannelName());
widget->show(); widget->show();
} }
void ChatWidgetHeader::menuChangeChannel() void ChatWidgetHeader::menuChangeChannel()
{ {
_chatWidget->showChangeChannelPopup(); this->chatWidget->showChangeChannelPopup();
} }
void ChatWidgetHeader::menuClearChat() void ChatWidgetHeader::menuClearChat()
{ {
+9 -11
View File
@@ -21,24 +21,22 @@ class ChatWidgetHeader : public QWidget
Q_OBJECT Q_OBJECT
public: public:
explicit ChatWidgetHeader(ChatWidget *parent); explicit ChatWidgetHeader(ChatWidget *_chatWidget);
ChatWidget *getChatWidget() const
{
return _chatWidget;
}
// Update palette from global color scheme
void updateColors(); void updateColors();
// Update channel text from chat widget
void updateChannelText(); void updateChannelText();
protected: protected:
void paintEvent(QPaintEvent *); virtual void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *event); virtual void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event); virtual void mouseMoveEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event); virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
private: private:
ChatWidget *const _chatWidget; ChatWidget *chatWidget;
QPoint _dragStart; QPoint _dragStart;
bool _dragging; bool _dragging;
+2 -2
View File
@@ -16,7 +16,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
bool NotebookPage::isDraggingSplit = false; bool NotebookPage::isDraggingSplit = false;
ChatWidget *NotebookPage::draggingSplit = NULL; ChatWidget *NotebookPage::draggingSplit = nullptr;
std::pair<int, int> NotebookPage::dropPosition = std::pair<int, int>(-1, -1); std::pair<int, int> NotebookPage::dropPosition = std::pair<int, int>(-1, -1);
NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab) NotebookPage::NotebookPage(QWidget *parent, NotebookTab *tab)
@@ -80,7 +80,7 @@ std::pair<int, int> NotebookPage::removeFromLayout(ChatWidget *widget)
continue; continue;
} }
widget->setParent(NULL); widget->setParent(nullptr);
bool isLastItem = vbox->count() == 0; bool isLastItem = vbox->count() == 0;