Blame style/adwaitatileset.h

Packit 8e9c33
#ifndef adwaitatileset_h
Packit 8e9c33
#define adwaitatileset_h
Packit 8e9c33
Packit 8e9c33
/*************************************************************************
Packit 8e9c33
 * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr>    *
Packit 8e9c33
 *                                                                       *
Packit 8e9c33
 * This program is free software; you can redistribute it and/or modify  *
Packit 8e9c33
 * it under the terms of the GNU General Public License as published by  *
Packit 8e9c33
 * the Free Software Foundation; either version 2 of the License, or     *
Packit 8e9c33
 * (at your option) any later version.                                   *
Packit 8e9c33
 *                                                                       *
Packit 8e9c33
 * This program is distributed in the hope that it will be useful,       *
Packit 8e9c33
 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
Packit 8e9c33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
Packit 8e9c33
 * GNU General Public License for more details.                          *
Packit 8e9c33
 *                                                                       *
Packit 8e9c33
 * You should have received a copy of the GNU General Public License     *
Packit 8e9c33
 * along with this program; if not, write to the                         *
Packit 8e9c33
 * Free Software Foundation, Inc.,                                       *
Packit 8e9c33
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
Packit 8e9c33
 *************************************************************************/
Packit 8e9c33
Packit 8e9c33
Packit 8e9c33
#include <QPixmap>
Packit 8e9c33
#include <QRect>
Packit 8e9c33
#include <QVector>
Packit 8e9c33
Packit 8e9c33
//* handles proper scaling of pixmap to match widget rect.
Packit 8e9c33
/**
Packit 8e9c33
tilesets are collections of stretchable pixmaps corresponding to a given widget corners, sides, and center.
Packit 8e9c33
corner pixmaps are never stretched. center pixmaps are
Packit 8e9c33
*/
Packit 8e9c33
namespace Adwaita
Packit 8e9c33
{
Packit 8e9c33
    class TileSet
Packit 8e9c33
    {
Packit 8e9c33
        public:
Packit 8e9c33
        /**
Packit 8e9c33
        Create a TileSet from a pixmap. The size of the bottom/right chunks is
Packit 8e9c33
        whatever is left over from the other chunks, whose size is specified
Packit 8e9c33
        in the required parameters.
Packit 8e9c33
Packit 8e9c33
        @param w1 width of the left chunks
Packit 8e9c33
        @param h1 height of the top chunks
Packit 8e9c33
        @param w2 width of the not-left-or-right chunks
Packit 8e9c33
        @param h2 height of the not-top-or-bottom chunks
Packit 8e9c33
        */
Packit 8e9c33
        TileSet(const QPixmap&, int w1, int h1, int w2, int h2 );
Packit 8e9c33
Packit 8e9c33
        //* empty constructor
Packit 8e9c33
        TileSet();
Packit 8e9c33
Packit 8e9c33
        //* destructor
Packit 8e9c33
        virtual ~TileSet()
Packit 8e9c33
        {}
Packit 8e9c33
Packit 8e9c33
        /**
Packit 8e9c33
        Flags specifying what sides to draw in ::render. Corners are drawn when
Packit 8e9c33
        the sides forming that corner are drawn, e.g. Top|Left draws the
Packit 8e9c33
        top-center, center-left, and top-left chunks. The center-center chunk is
Packit 8e9c33
        only drawn when Center is requested.
Packit 8e9c33
        */
Packit 8e9c33
        enum Tile {
Packit 8e9c33
            Top = 0x1,
Packit 8e9c33
            Left = 0x2,
Packit 8e9c33
            Bottom = 0x4,
Packit 8e9c33
            Right = 0x8,
Packit 8e9c33
            Center = 0x10,
Packit 8e9c33
            TopLeft = Top|Left,
Packit 8e9c33
            TopRight = Top|Right,
Packit 8e9c33
            BottomLeft = Bottom|Left,
Packit 8e9c33
            BottomRight = Bottom|Right,
Packit 8e9c33
            Ring = Top|Left|Bottom|Right,
Packit 8e9c33
            Horizontal = Left|Right|Center,
Packit 8e9c33
            Vertical = Top|Bottom|Center,
Packit 8e9c33
            Full = Ring|Center
Packit 8e9c33
        };
Packit 8e9c33
        Q_DECLARE_FLAGS(Tiles, Tile)
Packit 8e9c33
Packit 8e9c33
        /**
Packit 8e9c33
        Fills the specified rect with tiled chunks. Corners are never tiled,
Packit 8e9c33
        edges are tiled in one direction, and the center chunk is tiled in both
Packit 8e9c33
        directions. Partial tiles are used as needed so that the entire rect is
Packit 8e9c33
        perfectly filled. Filling is performed as if all chunks are being drawn.
Packit 8e9c33
        */
Packit 8e9c33
        void render(const QRect&, QPainter*, Tiles = Ring) const;
Packit 8e9c33
Packit 8e9c33
        //* return size associated to this tileset
Packit 8e9c33
        QSize size( void ) const
Packit 8e9c33
        { return QSize( _w1 + _w3, _h1 + _h3 ); }
Packit 8e9c33
Packit 8e9c33
        //* is valid
Packit 8e9c33
        bool isValid( void ) const
Packit 8e9c33
        { return _pixmaps.size() == 9; }
Packit 8e9c33
Packit 8e9c33
        //* returns pixmap for given index
Packit 8e9c33
        QPixmap pixmap( int index ) const
Packit 8e9c33
        { return _pixmaps[index]; }
Packit 8e9c33
Packit 8e9c33
        protected:
Packit 8e9c33
Packit 8e9c33
        //* shortcut to pixmap list
Packit 8e9c33
        using PixmapList = QVector<QPixmap>;
Packit 8e9c33
Packit 8e9c33
        //* initialize pixmap
Packit 8e9c33
        void initPixmap( PixmapList&, const QPixmap&, int w, int h, const QRect& );
Packit 8e9c33
Packit 8e9c33
        private:
Packit 8e9c33
Packit 8e9c33
        //* pixmap arry
Packit 8e9c33
        PixmapList _pixmaps;
Packit 8e9c33
Packit 8e9c33
        // dimensions
Packit 8e9c33
        int _w1;
Packit 8e9c33
        int _h1;
Packit 8e9c33
        int _w3;
Packit 8e9c33
        int _h3;
Packit 8e9c33
Packit 8e9c33
    };
Packit 8e9c33
Packit 8e9c33
}
Packit 8e9c33
Packit 8e9c33
Q_DECLARE_OPERATORS_FOR_FLAGS(Adwaita::TileSet::Tiles)
Packit 8e9c33
Packit 8e9c33
#endif //TILESET_H