"Fossies" - the Fresh Open Source Software Archive

Member "audacious-plugins-3.10.1/src/albumart-qt/albumart.cc" (26 Dec 2018, 3668 Bytes) of package /linux/misc/audacious-plugins-3.10.1.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "albumart.cc" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.10_vs_3.10.1.

    1 /*
    2  * albumart.cc
    3  * Copyright 2014 William Pitcock
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions are met:
    7  *
    8  * 1. Redistributions of source code must retain the above copyright notice,
    9  *    this list of conditions, and the following disclaimer.
   10  *
   11  * 2. Redistributions in binary form must reproduce the above copyright notice,
   12  *    this list of conditions, and the following disclaimer in the documentation
   13  *    provided with the distribution.
   14  *
   15  * This software is provided "as is" and without any warranty, express or
   16  * implied. In no event shall the authors be liable for any damages arising from
   17  * the use of this software.
   18  */
   19 
   20 #include <QLabel>
   21 #include <QPixmap>
   22 
   23 #include <libaudcore/drct.h>
   24 #include <libaudcore/i18n.h>
   25 #include <libaudcore/plugin.h>
   26 #include <libaudcore/hook.h>
   27 
   28 #include <libaudqt/libaudqt.h>
   29 
   30 class AlbumArtQt : public GeneralPlugin {
   31 public:
   32     static constexpr PluginInfo info = {
   33         N_("Album Art"),
   34         PACKAGE,
   35         nullptr, // about
   36         nullptr, // prefs
   37         PluginQtOnly
   38     };
   39 
   40     constexpr AlbumArtQt () : GeneralPlugin (info, false) {}
   41     void * get_qt_widget ();
   42 };
   43 
   44 #define MARGIN 4
   45 
   46 class ArtLabel : public QLabel {
   47 public:
   48     ArtLabel (QWidget * parent = 0, Qt::WindowFlags f = 0) : QLabel(parent, f)
   49     {
   50         init ();
   51     }
   52 
   53     ArtLabel (const QString & text, QWidget * parent = 0, Qt::WindowFlags f = 0) : QLabel (text, parent, f)
   54     {
   55         init ();
   56     }
   57 
   58     void update_art ()
   59     {
   60         origPixmap = QPixmap (audqt::art_request_current (0, 0));
   61         origSize = origPixmap.size ();
   62         drawArt ();
   63     }
   64 
   65     void clear ()
   66     {
   67         QLabel::clear ();
   68         origPixmap = QPixmap ();
   69     }
   70 
   71 protected:
   72     virtual void resizeEvent (QResizeEvent * event)
   73     {
   74         QLabel::resizeEvent (event);
   75         const QPixmap * pm = pixmap ();
   76 
   77         if ( ! origPixmap.isNull () && pm && ! pm->isNull () &&
   78                 (size ().width () <= origSize.width () + MARGIN ||
   79                  size ().height () <= origSize.height () + MARGIN ||
   80                  pm->size ().width () != origSize.width () ||
   81                  pm->size ().height () != origSize.height ()))
   82             drawArt ();
   83     }
   84 
   85 private:
   86     QPixmap origPixmap;
   87     QSize origSize;
   88 
   89     void init ()
   90     {
   91         clear ();
   92         setMinimumSize (MARGIN + 1, MARGIN + 1);
   93         setAlignment (Qt::AlignCenter);
   94     }
   95 
   96     void drawArt ()
   97     {
   98         if (origSize.width () <= size ().width () - MARGIN &&
   99             origSize.height () <= size ().height() - MARGIN)
  100             setPixmap (origPixmap);
  101         else
  102             setPixmap (origPixmap.scaled (size ().width () - MARGIN, size ().height () - MARGIN,
  103                         Qt::KeepAspectRatio, Qt::SmoothTransformation));
  104 
  105 #ifdef Q_OS_MAC
  106     repaint();
  107 #endif
  108     }
  109 };
  110 
  111 #undef MARGIN
  112 
  113 static void update (void *, ArtLabel * widget)
  114 {
  115     widget->update_art ();
  116 }
  117 
  118 static void clear (void *, ArtLabel * widget)
  119 {
  120     widget->clear ();
  121 }
  122 
  123 static void widget_cleanup (QObject * widget)
  124 {
  125     hook_dissociate ("playback ready", (HookFunction) update, widget);
  126     hook_dissociate ("playback stop", (HookFunction) clear, widget);
  127 }
  128 
  129 void * AlbumArtQt::get_qt_widget ()
  130 {
  131     ArtLabel * widget = new ArtLabel;
  132 
  133     QObject::connect (widget, &QObject::destroyed, widget_cleanup);
  134 
  135     hook_associate ("playback ready", (HookFunction) update, widget);
  136     hook_associate ("playback stop", (HookFunction) clear, widget);
  137 
  138     if (aud_drct_get_ready ())
  139         widget->update_art ();
  140 
  141     return widget;
  142 }
  143 
  144 EXPORT AlbumArtQt aud_plugin_instance;