summaryrefslogtreecommitdiffstats
blob: 67e3ae9a4f56ffb4ababe18512100144c951e18b (plain)
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
/*
 * Copyright (c) 2010-2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swift/QtUI/QtTabWidget.h>

#include <QLabel>
#include <QPainter>
#include <QPoint>

#include <Swift/QtUI/Trellis/QtDNDTabBar.h>

namespace Swift {

QtTabWidget::QtTabWidget(QWidget* parent) : QTabWidget(parent) {

}

QtTabWidget::~QtTabWidget() {

}

QTabBar* QtTabWidget::tabBar() {
    return QTabWidget::tabBar();
}

void QtTabWidget::setTabBar(QTabBar* tabBar) {
    QTabWidget::setTabBar(tabBar);
    if (dynamic_cast<QtDNDTabBar*>(tabBar)) {
        setAcceptDrops(true);
    }
    else {
        setAcceptDrops(false);
    }
}

void QtTabWidget::dragEnterEvent(QDragEnterEvent* event) {
    QtDNDTabBar* dndTabBar = dynamic_cast<QtDNDTabBar*>(tabBar());
    if (dndTabBar) {
        dndTabBar->dragEnterEvent(event);
    }
}

void QtTabWidget::dropEvent(QDropEvent* event) {
    QtDNDTabBar* dndTabBar = dynamic_cast<QtDNDTabBar*>(tabBar());
    if (dndTabBar) {
        dndTabBar->dropEvent(event);
    }
}

void QtTabWidget::paintEvent(QPaintEvent * event) {
    QTabWidget::paintEvent(event);
    if (count() == 0) {
        QLabel label;
        label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        label.setGeometry(QRect(QPoint(0,0), size()) - QMargins(10,10,10,10));
        label.setWordWrap(true);
        label.setText(tr("This empty cell is a placeholder for chat windows. You can move existing chats to this cell by dragging the tab over here. You can change the number of cells via the 'Change layout' dialog under the 'View' menu or by using the %1 shortcut.").arg(QKeySequence(tr("Ctrl+Alt+L")).toString(QKeySequence::NativeText)));
        QPainter painter(this);
        painter.drawPixmap(label.geometry().topLeft(), label.grab());
    }
}

}