summaryrefslogtreecommitdiffstats
path: root/src/dlgcoverartfullsize.cpp
blob: 1c39fae383f6f1884f648b5f2323dcf7334a1e7e (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
#include <QDesktopWidget>

#include "dlgcoverartfullsize.h"
#include "library/coverartutils.h"

DlgCoverArtFullSize::DlgCoverArtFullSize(QWidget* parent)
        : QDialog(parent) {
    setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
}

DlgCoverArtFullSize::~DlgCoverArtFullSize() {
}

void DlgCoverArtFullSize::init(CoverInfo info) {
    // TODO(rryan): don't do this in the main thread
    QImage cover = CoverArtUtils::loadCover(info);
    QPixmap pixmap;
    if (!cover.isNull()) {
        pixmap.convertFromImage(cover);
    }

    if (pixmap.isNull()) {
        return;
    }

    QWidgetList windows = QApplication::topLevelWidgets();
    QSize largestWindowSize;
    foreach (QWidget* pWidget, windows) {
        largestWindowSize = largestWindowSize.expandedTo(pWidget->size());
    }

    // If cover is bigger than Mixxx, it must be resized!
    // In this case, it need to do a small adjust to make
    // this dlg a bit smaller than the Mixxx window.
    QSize mixxxSize = largestWindowSize / qreal(1.2);
    if (pixmap.height() > mixxxSize.height()
            || pixmap.width() > mixxxSize.width()) {
        pixmap = pixmap.scaled(
            mixxxSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    }
    resize(pixmap.size());
    coverArt->setPixmap(pixmap);

    show();
    move(QApplication::desktop()->screenGeometry().center() - rect().center());
    raise();
    activateWindow();
}