1 // SPDX-License-Identifier: GPL-2.0-or-later OR MPL-1.1 OR LGPL-2.1-or-later 2 /* ***** BEGIN LICENSE BLOCK ***** 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * http://www.mozilla.org/MPL/ 9 * 10 * Software distributed under the License is distributed on an "AS IS" basis, 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 * for the specific language governing rights and limitations under the 13 * License. 14 * 15 * The Original Code is Eek Preview Stuffs. 16 * 17 * The Initial Developer of the Original Code is 18 * Jon A. Cruz. 19 * Portions created by the Initial Developer are Copyright (C) 2005-2008 20 * the Initial Developer. All Rights Reserved. 21 * 22 * Contributor(s): 23 * 24 * Alternatively, the contents of this file may be used under the terms of 25 * either the GNU General Public License Version 2 or later (the "GPL"), or 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 * in which case the provisions of the GPL or the LGPL are applicable instead 28 * of those above. If you wish to allow use of your version of this file only 29 * under the terms of either the GPL or the LGPL, and not to allow others to 30 * use your version of this file under the terms of the MPL, indicate your 31 * decision by deleting the provisions above and replace them with the notice 32 * and other provisions required by the GPL or the LGPL. If you do not delete 33 * the provisions above, a recipient may use your version of this file under 34 * the terms of any one of the MPL, the GPL or the LGPL. 35 * 36 * ***** END LICENSE BLOCK ***** */ 37 38 #ifndef SEEN_EEK_PREVIEW_H 39 #define SEEN_EEK_PREVIEW_H 40 41 #include <gtkmm/drawingarea.h> 42 43 /** 44 * @file 45 * Generic implementation of an object that can be shown by a preview. 46 */ 47 48 namespace Inkscape { 49 namespace UI { 50 namespace Widget { 51 52 enum PreviewStyle { 53 PREVIEW_STYLE_ICON = 0, 54 PREVIEW_STYLE_PREVIEW, 55 PREVIEW_STYLE_NAME, 56 PREVIEW_STYLE_BLURB, 57 PREVIEW_STYLE_ICON_NAME, 58 PREVIEW_STYLE_ICON_BLURB, 59 PREVIEW_STYLE_PREVIEW_NAME, 60 PREVIEW_STYLE_PREVIEW_BLURB 61 }; 62 63 enum ViewType { 64 VIEW_TYPE_LIST = 0, 65 VIEW_TYPE_GRID 66 }; 67 68 enum PreviewSize { 69 PREVIEW_SIZE_TINY = 0, 70 PREVIEW_SIZE_SMALL, 71 PREVIEW_SIZE_MEDIUM, 72 PREVIEW_SIZE_BIG, 73 PREVIEW_SIZE_BIGGER, 74 PREVIEW_SIZE_HUGE 75 }; 76 77 enum LinkType { 78 PREVIEW_LINK_NONE = 0, 79 PREVIEW_LINK_IN = 1, 80 PREVIEW_LINK_OUT = 2, 81 PREVIEW_LINK_OTHER = 4, 82 PREVIEW_FILL = 8, 83 PREVIEW_STROKE = 16, 84 PREVIEW_LINK_ALL = 31 85 }; 86 87 enum BorderStyle { 88 BORDER_NONE = 0, 89 BORDER_SOLID, 90 BORDER_WIDE, 91 BORDER_SOLID_LAST_ROW, 92 }; 93 94 class Preview : public Gtk::DrawingArea { 95 private: 96 int _scaledW; 97 int _scaledH; 98 99 int _r; 100 int _g; 101 int _b; 102 103 bool _hot; 104 bool _within; 105 bool _takesFocus; ///< flag to grab focus when clicked 106 ViewType _view; 107 PreviewSize _size; 108 unsigned int _ratio; 109 LinkType _linked; 110 unsigned int _border; 111 112 Glib::RefPtr<Gdk::Pixbuf> _previewPixbuf; 113 Glib::RefPtr<Gdk::Pixbuf> _scaled; 114 115 // signals 116 sigc::signal<void> _signal_clicked; 117 sigc::signal<void, int> _signal_alt_clicked; 118 119 void size_request(GtkRequisition *req) const; 120 121 protected: 122 void get_preferred_width_vfunc(int &minimal_width, int &natural_width) const override; 123 void get_preferred_height_vfunc(int &minimal_height, int &natural_height) const override; 124 bool on_draw(const Cairo::RefPtr<Cairo::Context> &cr) override; 125 bool on_button_press_event(GdkEventButton *button_event) override; 126 bool on_button_release_event(GdkEventButton *button_event) override; 127 bool on_enter_notify_event(GdkEventCrossing* event ) override; 128 bool on_leave_notify_event(GdkEventCrossing* event ) override; 129 130 public: 131 Preview(); get_focus_on_click()132 bool get_focus_on_click() const {return _takesFocus;} set_focus_on_click(bool focus_on_click)133 void set_focus_on_click(bool focus_on_click) {_takesFocus = focus_on_click;} 134 LinkType get_linked() const; 135 void set_linked(LinkType link); 136 void set_details(ViewType view, 137 PreviewSize size, 138 guint ratio, 139 guint border); 140 void set_color(int r, int g, int b); 141 void set_pixbuf(const Glib::RefPtr<Gdk::Pixbuf> &pixbuf); 142 static void set_size_mappings(guint count, GtkIconSize const* sizes); 143 signal_clicked()144 decltype(_signal_clicked) signal_clicked() {return _signal_clicked;} signal_alt_clicked()145 decltype(_signal_alt_clicked) signal_alt_clicked() {return _signal_alt_clicked;} 146 }; 147 148 } // namespace Widget 149 } // namespace UI 150 } // namespace Inkscape 151 152 #endif /* SEEN_EEK_PREVIEW_H */ 153 154 /* 155 Local Variables: 156 mode:c++ 157 c-file-style:"stroustrup" 158 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 159 indent-tabs-mode:nil 160 fill-column:99 161 End: 162 */ 163 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 164