LiVES  2.4.1-svn
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
widget-helper-qt.h
Go to the documentation of this file.
1 // widget-helper.h
2 // LiVES
3 // (c) G. Finch 2012 - 2015 <salsaman@gmail.com>
4 // released under the GNU GPL 3 or later
5 // see file ../COPYING or www.gnu.org for licensing details
6 
7 // this is kind of a fun project.
8 // a) for me to learn more C++
9 // b) to experiment with another widget toolkit
10 // c) to make LiVES a little less dependent on GKT+
11 
12 
13 #ifndef HAS_LIVES_WIDGET_HELPER_QT_H
14 #define HAS_LIVES_WIDGET_HELPER_QT_H
15 
16 #ifdef GUI_QT
17 // just for testing !!!!
18 
19 
20 #ifdef HAVE_X11
21 #include <X11/Xlib.h>
22 #endif
23 
24 using namespace std;
25 
26 #include <QtCore/QLinkedList>
27 
28 #include <QtGui/QScreen>
29 #include <QtGui/QWindow>
30 #include <QtGui/QTextCursor>
31 #include <QtGui/QTextDocumentFragment>
32 #include <QtGui/QShortcutEvent>
33 #include <QtGui/QWheelEvent>
34 #include <QtGui/QImageWriter>
35 #include <QtGui/QImageReader>
36 #include <QtCore/QDebug>
37 #include <QtCore/QTime>
38 #include <QtGui/QFont>
39 #include <QtGui/QFontDatabase>
40 #include <QtCore/QStandardPaths>
41 #include <QtCore/QLocale>
42 #include <QtCore/QMutableLinkedListIterator>
43 
44 #include <QtWidgets/QApplication>
45 #include <QtWidgets/QDesktopWidget>
46 #include <QtWidgets/QCompleter>
47 #include <QtWidgets/QLabel>
48 #include <QtWidgets/QColorDialog>
49 #include <QtWidgets/QWidget>
50 #include <QtWidgets/QWidgetAction>
51 #include <QtWidgets/QStyledItemDelegate>
52 #include <QtWidgets/QHeaderView>
53 #include <QtWidgets/QSplitter>
54 #include <QtWidgets/QLineEdit>
55 #include <QtWidgets/QPushButton>
56 #include <QtWidgets/QToolButton>
57 #include <QtWidgets/QToolBar>
58 #include <QtWidgets/QTableWidget>
59 #include <QtWidgets/QDialog>
60 #include <QtWidgets/QMessageBox>
61 #include <QtWidgets/QDialogButtonBox>
62 #include <QtWidgets/QBoxLayout>
63 #include <QtWidgets/QComboBox>
64 #include <QtWidgets/QMenu>
65 #include <QtWidgets/QMenuBar>
66 #include <QtWidgets/QLabel>
67 #include <QtWidgets/QMainWindow>
68 #include <QtWidgets/QFileDialog>
69 #include <QtWidgets/QLayout>
70 #include <QtWidgets/QTextEdit>
71 #include <QtWidgets/QTreeWidget>
72 #include <QtWidgets/QRadioButton>
73 #include <QtWidgets/QButtonGroup>
74 #include <QtWidgets/QProgressBar>
75 #include <QtWidgets/QDoubleSpinBox>
76 #include <QtWidgets/QCheckBox>
77 #include <QtWidgets/QShortcut>
78 #include <QtWidgets/QGridLayout>
79 #include <QtWidgets/QFrame>
80 #include <QtWidgets/QGroupBox>
81 #include <QtWidgets/QScrollArea>
82 #include <QtWidgets/QScrollBar>
83 
84 #include <QtGui/QColor>
85 #include <QtCore/QAbstractItemModel>
86 #include <QtWidgets/QAbstractSlider>
87 #include <QtWidgets/QAbstractButton>
88 #include <QtCore/QSharedPointer>
89 #include <QtGui/QStandardItemModel>
90 #include <QtCore/QModelIndex>
91 #include <QtCore/QTimer>
92 #include <QtCore/QThread>
93 #include <QtCore/QProcess>
94 #include <QtCore/QAbstractNativeEventFilter>
95 #include <QtCore/QCoreApplication>
96 
97 QApplication *qapp;
98 QTime *qtime;
99 
100 #define GTK_CHECK_VERSION(a,b,c) 1
101 
102 #define LIVES_LITTLE_ENDIAN 0
103 #define LIVES_BIG_ENDIAN 1
104 
105 #define LIVES_MAXINT INT_MAX
106 #define LIVES_MAXUINT32 UINT32_MAX
107 #define LIVES_MAXSIZE SIZE_MAX
108 #define LIVES_MAXFLOAT FLT_MAX
109 
110 #define LIVES_UNLIKELY(a) Q_UNLIKELY(a)
111 #define LIVES_LIKELY(a) Q_LIKELY(a)
112 
113 #define MAX_CURSOR_WIDTH 32
114 
115 #define G_GNUC_MALLOC
116 #define G_GNUC_PURE
117 #define G_GNUC_CONST
118 
119 typedef void *livespointer;
120 typedef const void *livesconstpointer;
121 
122 #define LIVES_INT_TO_POINTER(a) lives_int_to_pointer(a)
123 #define LIVES_UINT_TO_POINTER(a) lives_uint_to_pointer(a)
124 #define LIVES_POINTER_TO_INT(a) lives_pointer_to_int(a)
125 
126 LIVES_INLINE livespointer lives_int_to_pointer(int32_t a) {
127  return (livespointer)a;
128 }
129 
130 LIVES_INLINE livespointer lives_uint_to_pointer(uint32_t a) {
131  return (livespointer)a;
132 }
133 
134 LIVES_INLINE int32_t lives_pointer_to_int(livesconstpointer p) {
135  uint64_t xint = (uint64_t)p;
136  return (int32_t)(xint & 0xFFFF);
137 }
138 
139 typedef struct {
140  livespointer(*malloc)(size_t n_bytes);
141  livespointer(*realloc)(livespointer mem,
142  size_t n_bytes);
143  void (*free)(livespointer mem);
144  /* optional; set to NULL if not used ! */
145  livespointer(*calloc)(size_t n_blocks,
146  size_t n_block_bytes);
147  livespointer(*try_malloc)(size_t n_bytes);
148  livespointer(*try_realloc)(livespointer mem,
149  size_t n_bytes);
150 } LiVESMemVTable;
151 
152 LiVESMemVTable *static_alt_vtable;
153 
154 void (*lives_free)(livespointer ptr);
155 livespointer(*lives_malloc)(size_t size);
156 livespointer(*lives_realloc)(livespointer ptr, size_t new_size);
157 livespointer(*lives_try_malloc)(size_t size);
158 livespointer(*lives_try_realloc)(livespointer ptr, size_t new_size);
159 livespointer(_lives_calloc)(size_t n_blocks, size_t n_block_bytes);
160 
161 
162 livespointer malloc_wrapper(size_t size) {
163  livespointer ptr = (static_alt_vtable->malloc)(size);
164  Q_ASSERT(ptr != NULL);
165  return ptr;
166 }
167 
168 
169 livespointer realloc_wrapper(livespointer old_ptr, size_t new_size) {
170  livespointer ptr = (static_alt_vtable->realloc)(old_ptr,new_size);
171  Q_ASSERT(ptr != NULL);
172  return ptr;
173 }
174 
175 
176 livespointer try_malloc_wrapper(size_t size) {
177  return (static_alt_vtable->malloc)(size);
178 }
179 
180 
181 livespointer try_realloc_wrapper(livespointer old_ptr, size_t new_size) {
182  return (static_alt_vtable->realloc)(old_ptr,new_size);
183 }
184 
185 
186 LIVES_INLINE livespointer lives_malloc0(size_t size) {
187  livespointer ptr = (static_alt_vtable->calloc)(1,size);
188  Q_ASSERT(ptr != NULL);
189  return ptr;
190 }
191 
192 
193 LIVES_INLINE livespointer lives_try_malloc0(size_t size) {
194  return (static_alt_vtable->calloc)(1,size);
195 }
196 
197 
198 LIVES_INLINE livespointer lives_try_malloc0_n(size_t nmemb, size_t nmemb_bytes) {
199  return (static_alt_vtable->calloc)(nmemb,nmemb_bytes);
200 }
201 
202 
203 
204 #define NO_GTK
205 #include "support.h"
206 
207 extern char *trString;
208 
209 // TODO - move to support.c
210 char *translate(const char *String) {
211  delete trString; // be very careful, as trString is free()d automatically here
212  if (strlen(String)) {
213  QString qs = QString::fromLocal8Bit(dgettext(PACKAGE, String));
214  trString = strdup(qs.toUtf8().constData());
215  } else trString=strdup(String);
216  return trString;
217 }
218 
219 char *translate_with_plural(const char *String, const char *StringPlural, unsigned long int n) {
220  delete trString; // be very careful, as trString is free()d automatically here
221  if (strlen(String)) {
222  QString qs = QString::fromLocal8Bit(dngettext(PACKAGE, String, StringPlural, n));
223  trString = strdup(qs.toUtf8().constData());
224  } else trString=strdup(String);
225  return trString;
226 }
227 
228 
229 int lives_printerr(const char *format, ...) {
230  char *buff;
231  va_list args;
232  va_start(args, format);
233  int r = vasprintf(&buff, format, args);
234  va_end(args);
235  qDebug() << buff;
236  free(buff);
237  return r;
238 }
239 
240 
241 
242 #define lives_strdup(a) strdup(a)
243 #define lives_strndup(a,b) strndup(a,b)
244 
245 char *lives_strdup_printf(const char *format, ...) {
246  char *buff;
247  va_list args;
248  va_start(args, format);
249  int r = vasprintf(&buff, format, args);
250  r = r;
251  va_end(args);
252  return buff;
253 }
254 
255 int lives_snprintf(char *buff, size_t len, const char *format, ...) {
256  va_list args;
257  va_start(args, format);
258  int r = vsnprintf(buff, len, format, args);
259  va_end(args);
260  return r;
261 }
262 
263 
264 void lives_strfreev(char **str_array) {
265  if (str_array) {
266  for (int i = 0; str_array[i] != NULL; i++)
267  lives_free(str_array[i]);
268  lives_free(str_array);
269  }
270 }
271 
272 #define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
273 #define TOLOWER(c) (ISUPPER (c) ? (c) - 'A' + 'a' : (c))
274 
275 int lives_ascii_strcasecmp(const char *s1, const char *s2) {
276  int c1, c2;
277 
278  while (*s1 && *s2) {
279  c1 = (int)(uint8_t) TOLOWER(*s1);
280  c2 = (int)(uint8_t) TOLOWER(*s2);
281  if (c1 != c2)
282  return (c1 - c2);
283  s1++;
284  s2++;
285  }
286  return (((int)(uint8_t) *s1) - ((int)(uint8_t) *s2));
287 }
288 
289 
290 int lives_ascii_strncasecmp(const char *s1, const char *s2, size_t len) {
291  int c1, c2;
292 
293  while (len && *s1 && *s2) {
294  len--;
295  c1 = (int)(uint8_t) TOLOWER(*s1);
296  c2 = (int)(uint8_t) TOLOWER(*s2);
297  if (c1 != c2)
298  return (c1 - c2);
299  s1++;
300  s2++;
301  }
302  if (len) return (((int)(uint8_t) *s1) - ((int)(uint8_t) *s2));
303  else return 0;
304 }
305 
306 
307 char *lives_strconcat(const char *string1, ...) {
308  size_t l;
309  va_list args;
310  char *s;
311  char *concat;
312  char *ptr;
313  if (!string1)
314  return NULL;
315  l = 1 + strlen(string1);
316  va_start(args, string1);
317  s = va_arg(args, char *);
318  while (s) {
319  l += strlen(s);
320  s = va_arg(args, char *);
321  }
322  va_end(args);
323  concat = (char *)malloc(l);
324  ptr = concat;
325  ptr = stpcpy(ptr, string1);
326  va_start(args, string1);
327  s = va_arg(args, char *);
328  while (s) {
329  ptr = stpcpy(ptr, s);
330  s = va_arg(args, char *);
331  }
332  va_end(args);
333  return concat;
334 }
335 
336 
337 
338 char *lives_build_filename(const char *first, ...) {
339  char *fname = strdup(""), *tmp;
340  char *piece;
341  char sep = '/';
342  va_list args;
343 
344 #ifdef IS_MINGW
345  va_start(args, first);
346  while (1) {
347  piece = va_arg(args, char *);
348  if (piece == NULL) break;
349  if (strstr(piece,"\\")) {
350  sep = '\\';
351  break;
352  }
353  }
354  va_end(args);
355 #endif
356 
357  va_start(args, first);
358  while (1) {
359  piece = va_arg(args, char *);
360  if (piece == NULL) break;
361  tmp = lives_strdup_printf("%s%s%s",fname,sep,piece);
362  lives_free(fname);
363  fname = tmp;
364  }
365  va_end(args);
366 
367  QString qs(fname);
368  lives_free(fname);
369 #ifdef IS_MINGW
370  fname = strdup(QDir::cleanPath(qs).toUtf8().constData());
371 #else
372  fname = strdup(QDir::cleanPath(qs).toLocal8Bit().constData());
373 #endif
374  return fname;
375 }
376 
377 
378 char *lives_strstrip(char *string) {
379  QString qs = QString::fromUtf8(string);
380  qs.trimmed();
381  memcpy(string,qs.toUtf8().constData(),qs.toUtf8().size());
382  return string;
383 }
384 
385 
386 char *lives_strrstr(const char *haystack, const char *needle) {
387  size_t i;
388  size_t needle_len;
389  size_t haystack_len;
390  const char *p;
391  needle_len = strlen(needle);
392  haystack_len = strlen(haystack);
393  if (needle_len == 0)
394  return (char *)haystack;
395  if (haystack_len < needle_len)
396  return NULL;
397  p = haystack + haystack_len - needle_len;
398  while (p >= haystack) {
399  for (i = 0; i < needle_len; i++)
400  if (p[i] != needle[i])
401  goto next;
402  return (char *)p;
403 next:
404  p--;
405  }
406  return NULL;
407 }
408 
409 
410 
411 LIVES_INLINE char *lives_filename_to_utf8(const char *ostr, ssize_t len, size_t *bytes_read, size_t *bytes_written, void *error) {
412 #ifndef IS_MINGW
413  QString qs = QString::fromLocal8Bit(ostr);
414  return strdup(qs.toUtf8().constData());
415 #endif
416  return strdup(ostr);
417 }
418 
419 
420 LIVES_INLINE char *lives_filename_from_utf8(const char *ostr, ssize_t len, size_t *bytes_read, size_t *bytes_written, void *error) {
421 #ifndef IS_MINGW
422  QString qs = QString::fromUtf8(ostr);
423  return strdup(qs.toLocal8Bit().constData());
424 #endif
425  return strdup(ostr);
426 }
427 
428 
429 #ifndef IS_MINGW
430 #define LIVES_DIR_SEPARATOR_S "/"
431 #else
432 #define LIVES_DIR_SEPARATOR_S "\\"
433 #endif
434 
435 char *L2U8(const char *local_string) {
436 #ifndef IS_MINGW
437  QString qs = QString::fromLocal8Bit(local_string);
438  return strdup(qs.toUtf8().constData());
439 #else
440  return local_string;
441 #endif
442 }
443 
444 char *U82L(const char *utf8_string) {
445 #ifndef IS_MINGW
446  QString qs = QString::fromUtf8(utf8_string);
447  return strdup(qs.toLocal8Bit().constData());
448 #else
449  return utf8_string;
450 #endif
451 }
452 
453 
454 char *lives_utf8_strdown(char *string, size_t len) {
455  QString qs = QString::fromUtf8(string);
456  qs.toLower();
457  return strdup(qs.toUtf8().constData());
458 }
459 
460 
461 
462 #define ABS(a) qAbs(a)
463 
464 
465 char *lives_find_program_in_path(const char *prog) {
466  QString qs = QStandardPaths::findExecutable(prog);
467  if (qs == "") return NULL;
468  return strdup(qs.toLocal8Bit().constData());
469 }
470 
471 
472 
473 
474 
475 
476 #ifndef IS_MINGW
477 typedef bool boolean;
478 #endif
479 
480 
481 typedef boolean(*LiVESWidgetSourceFunc)(livespointer data);
482 
483 typedef int (*LiVESCompareFunc)(livesconstpointer a, livesconstpointer b);
484 
485 #ifndef FALSE
486 #define FALSE false
487 #endif
488 
489 #ifndef TRUE
490 #define TRUE true
491 #endif
492 
493 
494 extern "C" {
495  uint32_t lives_timer_add(uint32_t interval, LiVESWidgetSourceFunc function, livespointer data);
496 }
497 
498 #define G_PRIORITY_LOW 0
499 #define G_PRIORITY_HIGH 1
500 
501 LIVES_INLINE uint32_t lives_idle_add_full(int prio, LiVESWidgetSourceFunc function, livespointer data, livespointer destnot) {
502  return lives_timer_add(0, function, data);
503 }
504 
505 
506 LIVES_INLINE uint32_t lives_idle_add(LiVESWidgetSourceFunc function, livespointer data) {
507  return lives_timer_add(0, function, data);
508 }
509 
511 #define g_object_freeze_notify(a) (a)
512 #define g_object_thaw_notify(a) (a)
513 
514 
515 LIVES_INLINE void lives_set_application_name(const char *name) {
516  qapp->setApplicationName(QString::fromUtf8(name));
517 }
518 
519 
520 LIVES_INLINE const char *lives_get_application_name() {
521  return qapp->applicationName().toLocal8Bit().constData();
522 }
523 
524 
525 class SleeperThread : public QThread {
526 public:
527  static void msleep(unsigned long msecs) {
528  QThread::msleep(msecs);
529  }
530 };
531 
532 LIVES_INLINE void lives_usleep(ulong microsec) {
533  SleeperThread::msleep(microsec);
534 }
535 
536 
537 LIVES_INLINE int lives_mkdir_with_parents(const char *name, int mode) {
538 #ifndef IS_MINGW
539  mode_t omask = umask(mode);
540 #endif
541  QString qs = QString::fromUtf8(name);
542  QDir qd = QDir(qs);
543  bool ret = qd.mkpath(qs);
544 #ifndef IS_MINGW
545  umask(omask);
546 #endif
547  if (!ret) return -1;
548  return 0;
549 }
550 
551 #define lives_strtod(a,b) strtod(a,b)
552 
553 char *lives_path_get_basename(const char *path) {
554  QFileInfo qf(path);
555  QString qs = qf.fileName();
556  return strdup(qs.toUtf8().constData());
557 }
558 
559 char *lives_path_get_dirname(const char *path) {
560  QFileInfo qf(path);
561  QDir dir = qf.dir();
562  QString qs = dir.path();
563  return strdup(qs.toUtf8().constData());
564 }
565 
566 
567 typedef int LiVESFileTest;
568 #define LIVES_FILE_TEST_EXISTS 1
569 #define LIVES_FILE_TEST_IS_DIR 2
570 #define LIVES_FILE_TEST_IS_REGULAR 3
571 
572 
573 boolean lives_file_test(const char *fname, LiVESFileTest test) {
574  QFileInfo qf(fname);
575  if (test == LIVES_FILE_TEST_EXISTS) {
576  return qf.exists();
577  }
578  if (test == LIVES_FILE_TEST_IS_DIR) {
579  return qf.isDir();
580  }
581  if (test == LIVES_FILE_TEST_IS_REGULAR) {
582  return qf.isFile();
583  }
584  return FALSE;
585 }
586 
587 
588 char *lives_get_current_dir() {
589  QString qs = QDir::current().path();
590 #ifdef IS_MINGW
591  return strdup(qs.toUtf8().constData());
592 #else
593  return strdup(qs.toLocal8Bit().constData());
594 #endif
595 
596 }
597 
598 typedef struct {
599  ulong function;
600  livespointer data;
601 } LiVESClosure;
602 
603 typedef LiVESClosure LiVESWidgetClosure;
604 
605 
606 
608 
609 
610 typedef void (*LiVESPixbufDestroyNotify)(uchar *, livespointer);
611 
612 
613 typedef int lives_painter_content_t;
614 
615 
616 
617 typedef struct {
618  int code;
619  char *message;
620 } LiVESError;
621 
622 
623 LIVES_INLINE void lives_error_free(LiVESError *error) {
624  if (error->message != NULL) free(error->message);
625  free(error);
626 }
627 
628 #define lives_strerror(a) strerror(a)
629 
630 
631 typedef QScreen LiVESXScreen;
632 typedef QScreen LiVESXDisplay;
633 typedef QScreen LiVESXDevice;
634 
635 #ifndef HAVE_X11
636 typedef WId Window;
637 #endif
638 
639 typedef QFile LiVESIOChannel;
640 
641 
642 
643 //#define LIVES_TABLE_IS_GRID 1 // no "remove row" available
644 
645 
646 
647 typedef QStyle::StateFlag LiVESWidgetState;
648 
649 #define LIVES_WIDGET_STATE_NORMAL QStyle::State_Enabled
650 #define LIVES_WIDGET_STATE_ACTIVE QStyle::State_Active
651 #define LIVES_WIDGET_STATE_PRELIGHT QStyle::State_MouseOver
652 #define LIVES_WIDGET_STATE_SELECTED QStyle::State_Selected
653 
654 #define LIVES_WIDGET_STATE_INSENSITIVE QStyle::State_None
655 
656 #define LIVES_WIDGET_STATE_FOCUSED QStyle::State_HasFocus
657 
658 //#define LIVES_WIDGET_STATE_INCONSISTENT GTK_STATE_FLAG_INCONSISTENT
659 //#define LIVES_WIDGET_STATE_BACKDROP GTK_STATE_FLAG_BACKDROP
660 
661 #define LIVES_WIDGET_COLOR_HAS_ALPHA (1)
662 #define LIVES_WIDGET_COLOR_SCALE(x) (x)
663 #define LIVES_WIDGET_COLOR_SCALE_255(x) ((double)x/255.)
664 
665 
666 typedef Qt::KeyboardModifiers LiVESXModifierType;
667 
668 #define LIVES_CONTROL_MASK Qt::ControlModifier
669 #define LIVES_ALT_MASK Qt::AltModifier
670 #define LIVES_SHIFT_MASK Qt::ShiftModifier
671 #define LIVES_LOCK_MASK Qt::ShiftModifier
672 
673 
674 #define LIVES_KEY_Left (static_cast<uint32_t>(Qt::Key_Left))
675 #define LIVES_KEY_Right (static_cast<uint32_t>(Qt::Key_Right))
676 #define LIVES_KEY_Up (static_cast<uint32_t>(Qt::Key_Up))
677 #define LIVES_KEY_Down (static_cast<uint32_t>(Qt::Key_Down))
678 
679 #define LIVES_KEY_BackSpace (static_cast<uint32_t>(Qt::Key_Backspace))
680 #define LIVES_KEY_Return (static_cast<uint32_t>(Qt::Key_Return))
681 #define LIVES_KEY_Tab (static_cast<uint32_t>(Qt::Key_Tab))
682 #define LIVES_KEY_Home (static_cast<uint32_t>(Qt::Key_Home))
683 #define LIVES_KEY_End (static_cast<uint32_t>(Qt::Key_End))
684 #define LIVES_KEY_Slash (static_cast<uint32_t>(Qt::Key_Slash))
685 #define LIVES_KEY_Space (static_cast<uint32_t>(Qt::Key_Space))
686 #define LIVES_KEY_Plus (static_cast<uint32_t>(Qt::Key_Plus))
687 #define LIVES_KEY_Minus (static_cast<uint32_t>(Qt::Key_Minus))
688 #define LIVES_KEY_Equal (static_cast<uint32_t>(Qt::Key_Equal))
689 
690 #define LIVES_KEY_1 (static_cast<uint32_t>(Qt::Key_1))
691 #define LIVES_KEY_2 (static_cast<uint32_t>(Qt::Key_2))
692 #define LIVES_KEY_3 (static_cast<uint32_t>(Qt::Key_3))
693 #define LIVES_KEY_4 (static_cast<uint32_t>(Qt::Key_4))
694 #define LIVES_KEY_5 (static_cast<uint32_t>(Qt::Key_5))
695 #define LIVES_KEY_6 (static_cast<uint32_t>(Qt::Key_6))
696 #define LIVES_KEY_7 (static_cast<uint32_t>(Qt::Key_7))
697 #define LIVES_KEY_8 (static_cast<uint32_t>(Qt::Key_8))
698 #define LIVES_KEY_9 (static_cast<uint32_t>(Qt::Key_9))
699 #define LIVES_KEY_0 (static_cast<uint32_t>(Qt::Key_0))
700 
701 #define LIVES_KEY_a (static_cast<uint32_t>(Qt::Key_A))
702 #define LIVES_KEY_b (static_cast<uint32_t>(Qt::Key_B))
703 #define LIVES_KEY_c (static_cast<uint32_t>(Qt::Key_C))
704 #define LIVES_KEY_d (static_cast<uint32_t>(Qt::Key_D))
705 #define LIVES_KEY_e (static_cast<uint32_t>(Qt::Key_E))
706 #define LIVES_KEY_f (static_cast<uint32_t>(Qt::Key_F))
707 #define LIVES_KEY_g (static_cast<uint32_t>(Qt::Key_G))
708 #define LIVES_KEY_h (static_cast<uint32_t>(Qt::Key_H))
709 #define LIVES_KEY_i (static_cast<uint32_t>(Qt::Key_I))
710 #define LIVES_KEY_j (static_cast<uint32_t>(Qt::Key_J))
711 #define LIVES_KEY_k (static_cast<uint32_t>(Qt::Key_K))
712 #define LIVES_KEY_l (static_cast<uint32_t>(Qt::Key_L))
713 #define LIVES_KEY_m (static_cast<uint32_t>(Qt::Key_M))
714 #define LIVES_KEY_n (static_cast<uint32_t>(Qt::Key_N))
715 #define LIVES_KEY_o (static_cast<uint32_t>(Qt::Key_O))
716 #define LIVES_KEY_p (static_cast<uint32_t>(Qt::Key_P))
717 #define LIVES_KEY_q (static_cast<uint32_t>(Qt::Key_Q))
718 #define LIVES_KEY_r (static_cast<uint32_t>(Qt::Key_R))
719 #define LIVES_KEY_s (static_cast<uint32_t>(Qt::Key_S))
720 #define LIVES_KEY_t (static_cast<uint32_t>(Qt::Key_T))
721 #define LIVES_KEY_u (static_cast<uint32_t>(Qt::Key_U))
722 #define LIVES_KEY_v (static_cast<uint32_t>(Qt::Key_V))
723 #define LIVES_KEY_w (static_cast<uint32_t>(Qt::Key_W))
724 #define LIVES_KEY_x (static_cast<uint32_t>(Qt::Key_X))
725 #define LIVES_KEY_y (static_cast<uint32_t>(Qt::Key_Y))
726 #define LIVES_KEY_z (static_cast<uint32_t>(Qt::Key_Z))
727 
728 #define LIVES_KEY_F1 (static_cast<uint32_t>(Qt::Key_F1))
729 #define LIVES_KEY_F2 (static_cast<uint32_t>(Qt::Key_F2))
730 #define LIVES_KEY_F3 (static_cast<uint32_t>(Qt::Key_F3))
731 #define LIVES_KEY_F4 (static_cast<uint32_t>(Qt::Key_F4))
732 #define LIVES_KEY_F5 (static_cast<uint32_t>(Qt::Key_F5))
733 #define LIVES_KEY_F6 (static_cast<uint32_t>(Qt::Key_F6))
734 #define LIVES_KEY_F7 (static_cast<uint32_t>(Qt::Key_F7))
735 #define LIVES_KEY_F8 (static_cast<uint32_t>(Qt::Key_F8))
736 #define LIVES_KEY_F9 (static_cast<uint32_t>(Qt::Key_F9))
737 #define LIVES_KEY_F10 (static_cast<uint32_t>(Qt::Key_F10))
738 #define LIVES_KEY_F11 (static_cast<uint32_t>(Qt::Key_F11))
739 #define LIVES_KEY_F12 (static_cast<uint32_t>(Qt::Key_F12))
740 
741 #define LIVES_KEY_Page_Up (static_cast<uint32_t>(Qt::Key_PageUp))
742 #define LIVES_KEY_Page_Down (static_cast<uint32_t>(Qt::Key_PageDown))
743 
744 #define LIVES_KEY_Escape (static_cast<uint32_t>(Qt::Key_Escape))
745 
746 typedef int LiVESAccelFlags;
747 
748 typedef class LiVESAccelGroup LiVESAccelGroup;
749 typedef class LiVESWidget LiVESWidget;
750 
751 
752 typedef void LiVESXEvent;
753 typedef void LiVESXXEvent;
754 typedef void LiVESXEventMotion;
755 typedef void LiVESXEventFocus;
756 
757 typedef QCursor LiVESXCursor;
758 
759 
760 #define LIVES_SCROLL_UP 1
761 #define LIVES_SCROLL_DOWN 2
762 
763 typedef struct {
764  int direction;
765  LiVESXModifierType state;
766 } LiVESXEventScroll;
767 
768 
769 typedef struct {
770  int x;
771  int y;
772  int width;
773  int height;
774 } LiVESRect;
775 
776 
777 typedef struct {
778  int count;
779  LiVESRect area;
780 } LiVESXEventExpose;
781 
782 
783 typedef struct {
784  int time;
785  int type;
786  int button;
787 } LiVESXEventButton;
788 
789 #define LIVES_BUTTON_PRESS 1
790 #define LIVES_BUTTON_RELEASE 2
791 #define LIVES_BUTTON2_PRESS 3
792 
793 
794 typedef void LiVESXEventCrossing;
795 typedef void LiVESXEventConfigure;
796 typedef void LiVESXEventDelete;
797 
798 
799 typedef class LiVESObject LiVESObject;
800 
801 typedef void (*LiVESWidgetCallback)(LiVESWidget *widget, livespointer data);
802 
803 LiVESClosure *lives_cclosure_new(ulong func, livespointer data, livespointer dest_func) {
804  LiVESClosure *cl = new LiVESClosure;
805  cl->function = (ulong)func;
806  cl->data = data;
807 
808  return cl;
809  // TODO - something with dest_func: decref this when removed from accel, and call dest_func
810 }
811 
812 typedef boolean(*LiVESScrollEventCallback)(LiVESWidget *widget, LiVESXEventScroll *, livespointer data);
813 typedef boolean(*LiVESExposeEventCallback)(LiVESWidget *widget, LiVESXEventExpose *, livespointer data);
814 typedef boolean(*LiVESEnterEventCallback)(LiVESWidget *widget, LiVESXEventCrossing *, livespointer data);
815 typedef boolean(*LiVESButtonEventCallback)(LiVESWidget *widget, LiVESXEventButton *, livespointer data);
816 typedef boolean(*LiVESConfigureEventCallback)(LiVESWidget *widget, LiVESXEventConfigure *, livespointer data);
817 typedef boolean(*LiVESDeleteEventCallback)(LiVESWidget *widget, LiVESXEventDelete *, livespointer data);
818 typedef boolean(*LiVESAccelCallback)(LiVESAccelGroup *group, LiVESObject *obj, uint32_t keyval, LiVESXModifierType mod, livespointer data);
819 
820 #define LIVES_GUI_CALLBACK(a) (ulong)(a)
821 
822 
823 typedef void LiVESTargetEntry;
824 
825 typedef bool LiVESFilterReturn;
826 
827 #define LIVES_FILTER_REMOVE true
828 #define LIVES_FILTER_CONTINUE false
829 
830 
831 typedef struct {
832  ulong handler_id; // set for signals, 0 for key accels
833  QKeySequence ks; // set for key accels
834  LiVESAccelFlags flags;
835  LiVESAccelGroup *group;
836  QShortcut *shortcut; // created for key accels
837 
838  // for key accels, one or the other of these: - either we emit accel_signal, or we call closure
839  // for normal signals, both are set (name of signal and the closure it calls)
840  const char *signal_name; // or NULL, if not NULL we emit signal (or is set for signal)
841  LiVESClosure *closure; // or NULL, if not NULL we call closure
842  bool blocked;
843 } LiVESAccel;
844 
845 
846 
847 typedef struct {
848  // values from 0.0 -> 1.0
849  double red;
850  double green;
851  double blue;
852  double alpha;
853 } LiVESWidgetColor;
854 
855 
856 boolean return_true() {
857  return TRUE;
858 }
859 
860 
861 typedef uint32_t LiVESEventMask;
862 #define LIVES_EXPOSURE_MASK (1<<0)
863 #define LIVES_POINTER_MOTION_MASK (1<<1)
864 #define LIVES_POINTER_MOTION_HINT_MASK (1<<2)
865 #define LIVES_BUTTON_MOTION_MASK (1<<3)
866 #define LIVES_BUTTON1_MOTION_MASK (1<<4)
867 #define LIVES_BUTTON2_MOTION_MASK (1<<5)
868 #define LIVES_BUTTON3_MOTION_MASK (1<<6)
869 #define LIVES_BUTTON_PRESS_MASK (1<<7)
870 #define LIVES_BUTTON_RELEASE_MASK (1<<8)
871 #define LIVES_KEY_PRESS_MASK (1<<9)
872 #define LIVES_KEY_RELEASE_MASK (1<<10)
873 #define LIVES_ENTER_NOTIFY_MASK (1<<11)
874 #define LIVES_LEAVE_NOTIFY_MASK (1<<12)
875 #define LIVES_FOCUS_CHANGE_MASK (1<<13)
876 #define LIVES_STRUCTURE_MASK (1<<14)
877 #define LIVES_PROPERTY_CHANGE_MASK (1<<15)
878 #define LIVES_VISIBILITY_NOTIFY_MASK (1<<16)
879 #define LIVES_PROXIMITY_IN_MASK (1<<17)
880 #define LIVES_PROXIMITY_OUT_MASK (1<<18)
881 #define LIVES_SUBSTRUCTURE_MASK (1<<19)
882 #define LIVES_SCROLL_MASK (1<<20)
883 #define LIVES_TOUCH_MASK (1<<21)
884 #define LIVES_SMOOTH_SCROLL_MASK (1<<22)
885 
886 #define LIVES_ALL_EVENTS_MASK 0xFFFF
887 
888 // events
889 #define LIVES_WIDGET_EXPOSE_EVENT "update"
890 #define LIVES_WIDGET_SCROLL_EVENT "scroll_event"
891 #define LIVES_WIDGET_ENTER_EVENT "enter-event"
892 #define LIVES_WIDGET_BUTTON_PRESS_EVENT "button-press-event"
893 #define LIVES_WIDGET_CONFIGURE_EVENT "resize"
894 #define LIVES_WIDGET_DELETE_EVENT "close-event"
895 
896 // TODO - add: "motion_notify_event", "button_release_event", "leave-notify-event", "drag-data-received", "focus-out-event", "edited"
897 
898 
899 // signals
900 #define LIVES_WIDGET_CLICKED_EVENT "clicked"
901 #define LIVES_WIDGET_TOGGLED_EVENT "toggled"
902 #define LIVES_WIDGET_CHANGED_EVENT "changed"
903 #define LIVES_WIDGET_ACTIVATE_EVENT "activate"
904 #define LIVES_WIDGET_VALUE_CHANGED_EVENT "value-changed"
905 #define LIVES_WIDGET_SELECTION_CHANGED_EVENT "selection-changed"
906 #define LIVES_WIDGET_CURRENT_FOLDER_CHANGED_EVENT "current-folder-changed"
907 #define LIVES_WIDGET_RESPONSE_EVENT "response"
908 
909 // add "unmap", "color-set", "drag-data-received", "mode-changed", "accept-position", "edited", "set-focus-child", "state-changed", "switch-page", "size-prepared"
910 
911 extern "C" {
912  LiVESWidgetColor *lives_widget_color_copy(LiVESWidgetColor *c1orNULL, const LiVESWidgetColor *c2);
913 }
914 
915 static QString make_col(LiVESWidgetColor *col) {
916  QString qc = QString("rgba(%1,%2,%3,%4)")
917  .arg(col->red*255.)
918  .arg(col->green*255.)
919  .arg(col->blue*255.)
920  .arg(col->alpha*255.);
921  return qc;
922 }
923 
924 
925 typedef enum {
926  LIVES_OBJECT_TYPE_UNKNOWN,
927  LIVES_OBJECT_TYPE_TIMER,
928  LIVES_WIDGET_TYPE_BUTTON,
929  LIVES_WIDGET_TYPE_SPIN_BUTTON,
930  LIVES_WIDGET_TYPE_RADIO_BUTTON,
931  LIVES_WIDGET_TYPE_CHECK_BUTTON,
932  LIVES_WIDGET_TYPE_COLOR_BUTTON,
933  LIVES_WIDGET_TYPE_TOOL_BUTTON,
934  LIVES_WIDGET_TYPE_TOOLBAR,
935  LIVES_WIDGET_TYPE_BUTTON_BOX,
936  LIVES_WIDGET_TYPE_TEXT_VIEW,
937  LIVES_WIDGET_TYPE_SCALE,
938  LIVES_WIDGET_TYPE_SCROLLBAR,
939  LIVES_WIDGET_TYPE_SCROLLED_WINDOW,
940  LIVES_WIDGET_TYPE_PROGRESS_BAR,
941  LIVES_WIDGET_TYPE_PANED,
942  LIVES_WIDGET_TYPE_MENU,
943  LIVES_WIDGET_TYPE_MENU_ITEM,
944  LIVES_WIDGET_TYPE_TOOL_ITEM,
945  LIVES_WIDGET_TYPE_RADIO_MENU_ITEM,
946  LIVES_WIDGET_TYPE_CHECK_MENU_ITEM,
947  LIVES_WIDGET_TYPE_MENU_TOOL_BUTTON,
948  LIVES_WIDGET_TYPE_MENU_BAR,
949  LIVES_WIDGET_TYPE_ENTRY,
950  LIVES_WIDGET_TYPE_FRAME,
951  LIVES_WIDGET_TYPE_FILE_CHOOSER,
952  LIVES_WIDGET_TYPE_ARROW,
953  LIVES_WIDGET_TYPE_RULER,
954  LIVES_WIDGET_TYPE_COMBO,
955  LIVES_WIDGET_TYPE_TABLE,
956  LIVES_WIDGET_TYPE_DIALOG,
957  LIVES_WIDGET_TYPE_MESSAGE_DIALOG,
958  LIVES_WIDGET_TYPE_ALIGNMENT,
959  LIVES_WIDGET_TYPE_IMAGE,
960  LIVES_WIDGET_TYPE_LABEL,
961  LIVES_WIDGET_TYPE_NOTEBOOK,
962  LIVES_WIDGET_TYPE_TREE_VIEW,
963  LIVES_WIDGET_TYPE_HSEPARATOR,
964  LIVES_WIDGET_TYPE_VSEPARATOR,
965  LIVES_WIDGET_TYPE_MAIN_WINDOW,
966  LIVES_WIDGET_TYPE_SUB_WINDOW,
967  LIVES_WIDGET_TYPE_EVENT_BOX,
968  LIVES_WIDGET_TYPE_DRAWING_AREA,
969  LIVES_WIDGET_TYPE_HBOX,
970  LIVES_WIDGET_TYPE_VBOX,
971 } LiVESObjectType;
972 
973 
974 LIVES_INLINE QKeySequence make_qkey_sequence(uint32_t key, LiVESXModifierType mods) {
975  return static_cast<Qt::Key>(key) | mods;
976 }
977 
978 LIVES_INLINE uint32_t qkeysequence_get_key(QKeySequence ks) {
979  return ks[0] & 0x01FFFFFF;
980 }
981 
982 
983 LIVES_INLINE LiVESXModifierType qkeysequence_get_mod(QKeySequence ks) {
984  return static_cast<LiVESXModifierType>(ks[0] & 0xF2000000);
985 }
986 
987 
988 class evFilter : public QObject {
989 public:
990 
991 protected:
992  bool eventFilter(QObject *obj, QEvent *event);
993 
994 };
995 
996 
997 #ifdef HAVE_X11
998 
999 class nevfilter : public QAbstractNativeEventFilter {
1000 public:
1001 
1002  virtual bool nativeEventFilter(const QByteArray &eventType, livespointer message, long *);
1003 
1004 };
1005 
1006 #endif
1007 
1008 class LiVESObject : public QWidget {
1009  Q_OBJECT
1010 
1011 public:
1012 
1013  void block_signal(ulong handler_id);
1014  void block_signals(const char *signame);
1015  void block_signals(ulong func, livespointer data);
1016  void unblock_signal(ulong handler_id);
1017  void unblock_signals(const char *signame);
1018  void unblock_signals(ulong func, livespointer data);
1019  void disconnect_signal(ulong handler_id);
1020 
1021  void add_accel(LiVESAccel *accel);
1022  void add_accel(ulong handler_id, const char *signal_name, ulong funcptr, livespointer data);
1023  void add_accel(const char *signal_name, LiVESAccelGroup *group, uint32_t key, LiVESXModifierType mod, LiVESAccelFlags flags);
1024 
1025  boolean remove_accel(LiVESAccel *accel);
1026  boolean remove_accels(LiVESAccelGroup *, uint32_t key, LiVESXModifierType mod);
1027 
1028  boolean remove_accel_group(LiVESAccelGroup *group);
1029  void add_accel_group(LiVESAccelGroup *group);
1030 
1031  QList<LiVESAccelGroup *> get_accel_groups();
1032 
1033  QList<LiVESAccel *> get_accels_for(LiVESAccelGroup *group, QKeySequence ks);
1034  QList<LiVESAccel *> get_accels_for(ulong func, livespointer data);
1035  QList<LiVESAccel *> get_accels_for(const char *signame);
1036  LiVESAccel *get_accel_for(ulong handler_id);
1037 
1038  boolean activate_accel(uint32_t key, LiVESXModifierType mod);
1039  boolean activate_accel(QKeySequence ks);
1040 
1041  void remove_all_accels();
1042 
1043  LiVESObject() {
1044  init();
1045  };
1046 
1047 
1048  LiVESObject(const LiVESObject &xobj) {
1049  init();
1050  type = xobj.type;
1051  }
1052 
1053  void ref_sink() {
1054  if (floating) floating = false;
1055  else inc_refcount();
1056  }
1057 
1058  void inc_refcount() {
1059  refcount++;
1060  }
1061 
1062  void dec_refcount() {
1063  if (--refcount == 0) {
1064  finalise();
1065  }
1066  }
1067 
1068  void no_refcount() {
1069  refcount = 0;
1070  }
1071 
1072 
1073  void set_type(LiVESObjectType xtype) {
1074  type = xtype;
1075  }
1076 
1077  LiVESObjectType get_type() {
1078  return type;
1079  }
1080 
1081 private:
1082  bool floating;
1083  int refcount;
1084  evFilter *eFilter;
1085  QList<LiVESAccel *>accels;
1086  QList<LiVESAccelGroup *>accel_groups;
1087  LiVESObjectType type;
1088 
1089  void init() {
1090  eFilter = new evFilter();
1091  (static_cast<QObject *>(this))->installEventFilter(eFilter);
1092  refcount = 1;
1093  type = LIVES_OBJECT_TYPE_UNKNOWN;
1094  }
1095 
1096  void finalise(void) {
1097  (static_cast<QObject *>(this))->deleteLater(); // schedule for deletion
1098 
1099  // remove us from all accel_groups
1100  while (accel_groups.size() > 0) {
1101  remove_accel_group(accel_groups[0]);
1102  }
1103 
1104  remove_all_accels();
1105  }
1106 
1107 };
1108 
1109 
1110 typedef struct LiVESList LiVESList;
1111 
1112 struct LiVESList {
1113  livesconstpointer data;
1114  LiVESList *prev;
1115  LiVESList *next;
1116 };
1117 
1118 
1119 typedef struct LiVESSList LiVESSList;
1120 
1121 struct LiVESSList {
1122  livesconstpointer data;
1123  LiVESSList *next;
1124 };
1125 
1126 typedef LiVESList LiVESDList;
1127 
1128 
1129 LIVES_INLINE livesconstpointer lives_list_nth_data(LiVESList *list, uint32_t n) {
1130  for (unsigned int i = 0; i < n && list != NULL; i++) list = list->next;
1131  if (list == NULL) return NULL;
1132  livesconstpointer data = list->data;
1133  return data;
1134 }
1135 
1136 LIVES_INLINE LiVESList *lives_list_nth(LiVESList *list, uint32_t n) {
1137  for (unsigned int i = 0; i < n && list != NULL; i++) list = list->next;
1138  return list;
1139 }
1140 
1141 LIVES_INLINE livesconstpointer lives_slist_nth_data(LiVESSList *list, uint32_t n) {
1142  for (unsigned int i = 0; i < n && list != NULL; i++) list = list->next;
1143  if (list == NULL) return NULL;
1144  livesconstpointer data = list->data;
1145  return data;
1146 }
1147 
1148 LIVES_INLINE int lives_list_length(LiVESList *list) {
1149  int i;
1150  for (i = 0; list != NULL; i++) list = list->next;
1151  return i;
1152 }
1153 
1154 LIVES_INLINE int lives_slist_length(LiVESSList *list) {
1155  int i;
1156  for (i = 0; list != NULL; i++) list = list->next;
1157  return i;
1158 }
1159 
1160 
1161 
1162 LIVES_INLINE LiVESList *lives_list_remove(LiVESList *list, livesconstpointer data) {
1163  LiVESList *olist = list;
1164  for (int i = 0; list->data != data && list != NULL; i++) list = list->next;
1165  if (list == NULL) return NULL;
1166  if (list->prev != NULL) list->prev->next = list->next;
1167  else olist = list->next;
1168  if (list->next != NULL) list->next->prev = list->prev;
1169 
1170  list->next = list->prev = NULL;
1171 
1172  return olist;
1173 }
1174 
1175 
1176 LIVES_INLINE LiVESList *lives_list_remove_link(LiVESList *olist, LiVESList *list) {
1177  if (olist == NULL) return NULL;
1178 
1179  if (list->prev != NULL) list->prev->next = list->next;
1180  else olist = list->next;
1181  if (list->next != NULL) list->next->prev = list->prev;
1182 
1183  list->next = list->prev = NULL;
1184 
1185  return olist;
1186 }
1187 
1188 
1189 LIVES_INLINE LiVESSList *lives_slist_remove(LiVESSList *list, livesconstpointer data) {
1190  LiVESSList *olist = list, *xlist = list;
1191  for (int i = 0; list->data != data && list != NULL; i++) {
1192  xlist = list;
1193  list = list->next;
1194  }
1195  if (list == NULL) return NULL;
1196 
1197  xlist->next = list->next;
1198 
1199  if (list == olist) olist = list->next;
1200 
1201  list->next = NULL;
1202 
1203  return olist;
1204 }
1205 
1206 
1207 LIVES_INLINE LiVESList *lives_list_append(LiVESList *list, livesconstpointer data) {
1208  LiVESList *olist=NULL, *xlist=list;
1209 
1210  while (list != NULL) {
1211  olist = list;
1212  list = list->next;
1213  }
1214 
1215  LiVESList *elem = (LiVESList *)malloc(sizeof(LiVESList));
1216  elem->data = data;
1217  elem->next = NULL;
1218  elem->prev = olist;
1219 
1220  if (olist == NULL) xlist = elem;
1221  return xlist;
1222 }
1223 
1224 
1225 LIVES_INLINE LiVESSList *lives_slist_append(LiVESSList *list, livesconstpointer data) {
1226  LiVESSList *olist=NULL, *xlist=list;
1227 
1228  while (list != NULL) {
1229  olist = list;
1230  list = list->next;
1231  }
1232 
1233  LiVESSList *elem = (LiVESSList *)malloc(sizeof(LiVESSList));
1234  elem->data = data;
1235  elem->next = NULL;
1236 
1237  if (olist == NULL) xlist = elem;
1238  return xlist;
1239 }
1240 
1241 
1242 LIVES_INLINE LiVESList *lives_list_prepend(LiVESList *list, livesconstpointer data) {
1243  LiVESList *elem = (LiVESList *)malloc(sizeof(LiVESList));
1244  elem->data = data;
1245  elem->next = list;
1246  elem->prev = NULL;
1247  return elem;
1248 }
1249 
1250 
1251 LIVES_INLINE LiVESSList *lives_slist_prepend(LiVESSList *list, livesconstpointer data) {
1252  LiVESSList *elem = (LiVESSList *)malloc(sizeof(LiVESSList));
1253  elem->data = data;
1254  elem->next = list;
1255  return elem;
1256 }
1257 
1258 
1259 LIVES_INLINE LiVESList *lives_list_insert(LiVESList *list, livespointer data, int pos) {
1260  if (pos == 0) return lives_list_prepend(list, data);
1261 
1262  LiVESList *xlist = list, *olist = NULL;
1263 
1264  while (list != NULL && pos != 0) {
1265  olist = list;
1266  list = list->next;
1267  pos--;
1268  }
1269 
1270  LiVESList *elem = (LiVESList *)malloc(sizeof(LiVESList));
1271  elem->data = data;
1272  elem->next = olist->next;
1273  olist->next = elem;
1274  if (elem->next != NULL) elem->next->prev = elem;
1275  elem->prev = olist;
1276 
1277  if (xlist == NULL) xlist = elem;
1278  return xlist;
1279 
1280 }
1281 
1282 
1283 
1284 LIVES_INLINE LiVESList *lives_list_find(LiVESList *list, livesconstpointer data) {
1285  while (list != NULL) {
1286  if (list->data == data) return list;
1287  list = list->next;
1288  }
1289  return NULL;
1290 }
1291 
1292 
1293 LIVES_INLINE LiVESList *lives_list_find_custom(LiVESList *list, livesconstpointer data, LiVESCompareFunc func) {
1294  while (list != NULL) {
1295  if (! func(list->data, data))
1296  return list;
1297  list = list->next;
1298  }
1299  return NULL;
1300 }
1301 
1302 
1303 
1304 LIVES_INLINE void lives_list_free(LiVESList *list) {
1305  LiVESList *nlist;
1306  while (list != NULL) {
1307  nlist = list->next;
1308  free(list);
1309  list = nlist;
1310  }
1311 }
1312 
1313 
1314 LIVES_INLINE void lives_slist_free(LiVESSList *list) {
1315  LiVESSList *nlist;
1316  while (list != NULL) {
1317  nlist = list->next;
1318  free(list);
1319  list = nlist;
1320  }
1321 }
1322 
1323 
1324 LIVES_INLINE LiVESList *lives_list_previous(LiVESList *list) {
1325  if (list == NULL) return NULL;
1326  return list->prev;
1327 }
1328 
1329 
1330 LIVES_INLINE LiVESList *lives_list_last(LiVESList *list) {
1331  if (list == NULL) return NULL;
1332  while (list->next != NULL) list=list->next;
1333  return list;
1334 }
1335 
1336 
1337 
1338 LIVES_INLINE LiVESList *lives_list_delete_link(LiVESList *list, LiVESList *link) {
1339  list = lives_list_remove_link(list, link);
1340  free(link);
1341  return list;
1342 }
1343 
1344 
1345 LIVES_INLINE LiVESList *lives_list_copy(LiVESList *list) {
1346  LiVESList *new_list = NULL;
1347  while (list != NULL) {
1348  lives_list_append(new_list, list->data);
1349  list = list->next;
1350  }
1351  return new_list;
1352 }
1353 
1354 
1355 LIVES_INLINE LiVESList *lives_list_concat(LiVESList *a, LiVESList *b) {
1356  LiVESList *xlist = lives_list_last(a);
1357  xlist->next = b;
1358  b->prev = xlist;
1359  return a;
1360 }
1361 
1362 
1363 
1364 char **lives_strsplit(const char *string, const char *delimiter, int max_tokens) {
1365  LiVESSList *string_list = NULL,*slist;
1366  char **str_array;
1367  const char *s;
1368  uint32_t n = 0;
1369  const char *remainder;
1370  if (max_tokens < 1)
1371  max_tokens = INT_MAX;
1372  remainder = string;
1373  s = strstr(remainder, delimiter);
1374  if (s) {
1375  size_t delimiter_len = strlen(delimiter);
1376  while (--max_tokens && s) {
1377  size_t len;
1378  len = s - remainder;
1379  string_list = lives_slist_prepend(string_list, lives_strndup(remainder, len));
1380  n++;
1381  remainder = s + delimiter_len;
1382  s = strstr(remainder, delimiter);
1383  }
1384  }
1385  if (*string) {
1386  n++;
1387  string_list = lives_slist_prepend(string_list, lives_strdup(remainder));
1388  }
1389  str_array = (char **)lives_malloc((n + 1) * sizeof(char *));
1390  str_array[n--] = NULL;
1391  for (slist = string_list; slist; slist = slist->next)
1392  str_array[n--] = (char *)slist->data;
1393  lives_slist_free(string_list);
1394  return str_array;
1395 }
1396 
1397 
1398 
1399 char *lives_strdelimit(char *string, const char *delimiters, char new_delim) {
1400  char *c;
1401  for (c = string; *c; c++) {
1402  if (strchr(delimiters, *c))
1403  *c = new_delim;
1404  }
1405  return string;
1406 }
1407 
1408 
1409 
1410 
1411 char *lives_strstr_len(const char *haystack, ssize_t haystack_len, const char *needle) {
1412  if (haystack_len < 0)
1413  return (char *)strstr(haystack, needle);
1414  else {
1415  const char *p = haystack;
1416  size_t needle_len = strlen(needle);
1417  const char *end;
1418  size_t i;
1419  if (needle_len == 0)
1420  return (char *)haystack;
1421  if (haystack_len < needle_len)
1422  return NULL;
1423  end = haystack + haystack_len - needle_len;
1424  while (p <= end && *p) {
1425  for (i = 0; i < needle_len; i++)
1426  if (p[i] != needle[i])
1427  goto next;
1428  return (char *)p;
1429 next:
1430  p++;
1431  }
1432  return NULL;
1433  }
1434 }
1435 
1436 
1437 
1438 #define ICON_SCALE(a) ((int)(1.0 * a))
1439 typedef QSize LiVESIconSize;
1440 #define LIVES_ICON_SIZE_INVALID QSize(0,0)
1441 #define LIVES_ICON_SIZE_MENU QSize(ICON_SCALE(16),ICON_SCALE(16))
1442 #define LIVES_ICON_SIZE_SMALL_TOOLBAR QSize(ICON_SCALE(16),ICON_SCALE(16))
1443 #define LIVES_ICON_SIZE_LARGE_TOOLBAR QSize(ICON_SCALE(24),ICON_SCALE(24))
1444 #define LIVES_ICON_SIZE_BUTTON QSize(ICON_SCALE(16),ICON_SCALE(16))
1445 #define LIVES_ICON_SIZE_DND QSize(ICON_SCALE(32),ICON_SCALE(32))
1446 #define LIVES_ICON_SIZE_DIALOG QSize(ICON_SCALE(48),ICON_SCALE(48))
1447 
1448 
1449 typedef Qt::TransformationMode LiVESInterpType;
1450 #define LIVES_INTERP_BEST Qt::SmoothTransformation
1451 #define LIVES_INTERP_NORMAL Qt::SmoothTransformation
1452 #define LIVES_INTERP_FAST Qt::FastTransformation
1453 
1454 typedef int LiVESResponseType;
1455 #define LIVES_RESPONSE_NONE QDialogButtonBox::InvalidRole
1456 #define LIVES_RESPONSE_OK QDialogButtonBox::AcceptRole
1457 #define LIVES_RESPONSE_CANCEL QDialogButtonBox::RejectRole
1458 
1459 #define LIVES_RESPONSE_ACCEPT QDialogButtonBox::AcceptRole
1460 
1461 #define LIVES_RESPONSE_YES QDialogButtonBox::YesRole
1462 #define LIVES_RESPONSE_NO QDialogButtonBox::NoRole
1463 
1464 #define LIVES_RESPONSE_INVALID QDialogButtonBox::InvalidRole
1465 #define LIVES_RESPONSE_SHOW_DETAILS 100
1466 
1467 #define LIVES_RESPONSE_RETRY 101
1468 #define LIVES_RESPONSE_ABORT 102
1469 #define LIVES_RESPONSE_RESET 103
1470 
1471 typedef QStyle::StandardPixmap LiVESArrowType;
1472 #define LIVES_ARROW_UP QStyle::SP_ArrowUp
1473 #define LIVES_ARROW_DOWN QStyle::SP_ArrowDown
1474 #define LIVES_ARROW_LEFT QStyle::SP_ArrowLeft
1475 #define LIVES_ARROW_RIGHT QStyle::SP_ArrowRight
1476 #define LIVES_ARROW_NONE -1
1477 
1478 class LiVESWidget : public LiVESObject {
1479  Q_OBJECT
1480 
1481 public:
1482 
1483  Q_PROPERTY(bool prelight READ get_prelight WRITE set_prelight)
1484 
1485  void set_prelight(bool val) {
1486  (static_cast<QObject *>(static_cast<QWidget *>(this)))->setProperty("prelight", val);
1487  }
1488 
1489  bool get_prelight() {
1490  QVariant qv = (static_cast<QObject *>(static_cast<QWidget *>(this)))->property("prelight");
1491  return qv.value<bool>();
1492  }
1493 
1494  void set_fg_color(LiVESWidgetState state, const LiVESWidgetColor *col);
1495  void set_bg_color(LiVESWidgetState state, const LiVESWidgetColor *col);
1496  void set_base_color(LiVESWidgetState state, const LiVESWidgetColor *col);
1497  void set_text_color(LiVESWidgetState state, const LiVESWidgetColor *col);
1498 
1499  LiVESWidgetColor *get_fg_color(LiVESWidgetState state);
1500  LiVESWidgetColor *get_bg_color(LiVESWidgetState state);
1501 
1502  void update_stylesheet();
1503 
1504 
1505  LiVESWidget() : parent(NULL) {
1506 
1507  QVariant qv = QVariant::fromValue(static_cast<LiVESObject *>(this));
1508  (static_cast<QWidget *>(this))->setProperty("LiVESObject", qv);
1509 
1510  fg_norm=bg_norm=base_norm=text_norm=NULL;
1511  fg_act=bg_act=base_act=text_act=NULL;
1512  fg_insen=bg_insen=base_insen=text_insen=NULL;
1513  fg_hover=bg_hover=base_hover=text_hover=NULL;
1514  fg_sel=bg_sel=base_sel=text_sel=NULL;
1515  state = LIVES_WIDGET_STATE_NORMAL;
1516  widgetName = QString("%1").arg(ulong_random());
1517  events_mask = LIVES_EXPOSURE_MASK;
1518  onetime_events_mask = 0;
1519 
1520  static_cast<QObject *>(static_cast<QWidget *>(this))->connect(static_cast<QObject *>(static_cast<QWidget *>(this)),
1521  SIGNAL(destroyed()),
1522  static_cast<QObject *>(static_cast<QWidget *>(this)),
1523  SLOT(onDestroyed()));
1524 
1525  children = NULL;
1526  }
1527 
1528  void onDestroyed() {
1529  // if has child widgets, try to remove them and dec_refcount()
1530  // if widget is a toolitem/menuitem, remove its actions
1531 
1532  // TODO - this should never get called, instead we should call dec_refcount()
1533 
1534 
1535  }
1536 
1537  ~LiVESWidget();
1538 
1539 
1540  void add_child(LiVESWidget *child) {
1541  if (child->parent != NULL) return;
1542  child->set_parent(this);
1543  child->ref_sink();
1544  children = lives_list_append(children,child);
1545  }
1546 
1547  void remove_child(LiVESWidget *child) {
1548  children = lives_list_remove(children,child);
1549  child->set_parent(NULL);
1550  child->dec_refcount();
1551  }
1552 
1553  void set_parent(LiVESWidget *new_parent) {
1554  parent = new_parent;
1555  }
1556 
1557  LiVESWidget *get_parent() {
1558  return parent;
1559  }
1560 
1561  QString get_name() {
1562  return widgetName;
1563  }
1564 
1565  void set_events(uint32_t mask) {
1566  events_mask = mask;
1567  }
1568 
1569  void add_onetime_event_block(uint32_t mask) {
1570  onetime_events_mask |= mask;
1571  }
1572 
1573  void remove_onetime_event_block(uint32_t mask) {
1574  if (onetime_events_mask & mask) onetime_events_mask ^= mask;
1575  }
1576 
1577  uint32_t get_onetime_events_block() {
1578  return onetime_events_mask;
1579  }
1580 
1581  uint32_t get_events() {
1582  return events_mask;
1583  }
1584 
1585  int count_children() {
1586  return lives_list_length(children);
1587  }
1588 
1589  LiVESList *get_children() {
1590  return children;
1591  }
1592 
1593  void set_children(LiVESList *xchildren) {
1594  lives_list_free(children);
1595  children = xchildren;
1596  }
1597 
1598  LiVESWidget *get_child(int index) {
1599  return (LiVESWidget *)lives_list_nth_data(children,index);
1600  }
1601 
1602 
1603  int get_child_index(LiVESWidget *child) {
1604  LiVESList *xchildren = children;
1605  int i;
1606  for (i = 0; xchildren != NULL; i++) {
1607  if (xchildren->data == child) return i;
1608  }
1609  return -1;
1610  }
1611 
1612  LiVESWidgetState get_state() {
1613  return state;
1614  }
1615 
1616  void set_state(LiVESWidgetState xstate) {
1617  state = xstate;
1618 
1619  if (state & LIVES_WIDGET_STATE_INSENSITIVE) {
1620  setEnabled(false);
1621  } else {
1622  setEnabled(true);
1623  }
1624 
1625 
1626  if (state & LIVES_WIDGET_STATE_PRELIGHT) {
1627  if (!get_prelight()) set_prelight(true);
1628  } else {
1629  if (get_prelight()) set_prelight(false);
1630  }
1631 
1632  }
1633 
1634 
1635 public slots:
1636  void cb_wrapper_clicked() {
1637  // "clicked" callback
1638  call_accels_for(LIVES_WIDGET_CLICKED_EVENT);
1639  }
1640 
1641  void cb_wrapper_toggled() {
1642  // "toggled" callback
1643  call_accels_for(LIVES_WIDGET_CLICKED_EVENT);
1644  }
1645 
1646 
1647  void cb_wrapper_changed() {
1648  // "changed" callback
1649  call_accels_for(LIVES_WIDGET_CHANGED_EVENT);
1650  }
1651 
1652 
1653  void cb_wrapper_value_changed() {
1654  // "value-changed" callback
1655  call_accels_for(LIVES_WIDGET_VALUE_CHANGED_EVENT);
1656  }
1657 
1658  void cb_wrapper_selection_changed() {
1659  // "selection-changed" callback
1660  call_accels_for(LIVES_WIDGET_SELECTION_CHANGED_EVENT);
1661  }
1662 
1663  void cb_wrapper_current_folder_changed() {
1664  // "selection-changed" callback
1665  call_accels_for(LIVES_WIDGET_CURRENT_FOLDER_CHANGED_EVENT);
1666  }
1667 
1668  void cb_wrapper_activate() {
1669  // "activate" callback
1670  call_accels_for(LIVES_WIDGET_ACTIVATE_EVENT);
1671  }
1672 
1673  void cb_wrapper_response() {
1674  // "response" callback
1675  call_accels_for(LIVES_WIDGET_RESPONSE_EVENT);
1676  }
1677 
1678 private:
1679  LiVESList *children;
1680  LiVESWidget *parent;
1681  QString widgetName;
1682 
1683  LiVESWidgetColor *fg_norm,*bg_norm,*base_norm,*text_norm;
1684  LiVESWidgetColor *fg_act,*bg_act,*base_act,*text_act;
1685  LiVESWidgetColor *fg_insen,*bg_insen,*base_insen,*text_insen;
1686  LiVESWidgetColor *fg_hover,*bg_hover,*base_hover,*text_hover;
1687  LiVESWidgetColor *fg_sel,*bg_sel,*base_sel,*text_sel;
1688 
1689  LiVESWidgetState state;
1690 
1691  uint32_t events_mask;
1692  uint32_t onetime_events_mask;
1693 
1694  void call_accels_for(const char *type) {
1695  QList<LiVESAccel *> ql = get_accels_for(type);
1696  for (int i=0; i < ql.size(); i++) {
1697  LiVESWidgetCallback *cb = (LiVESWidgetCallback *)ql[i]->closure->function;
1698  (*cb)(this, ql[i]->closure->data);
1699  }
1700  }
1701 
1702 };
1703 
1704 
1705 #define LIVES_IS_WIDGET_OBJECT(a) 1
1706 #define LIVES_IS_WIDGET(a) 1
1707 #define LIVES_IS_CONTAINER(a) 1
1708 #define LIVES_IS_XWINDOW(a) 1
1709 
1710 #define LIVES_IS_BUTTON(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_BUTTON || \
1711  static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_CHECK_BUTTON)
1712 #define LIVES_IS_PUSH_BUTTON(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_BUTTON || \
1713  static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_RADIO_BUTTON)
1714 #define LIVES_IS_RANGE(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SCALE || \
1715  static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SCROLLBAR)
1716 #define LIVES_IS_LABEL(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_LABEL)
1717 #define LIVES_IS_TOGGLE_BUTTON(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_CHECK_BUTTON)
1718 #define LIVES_IS_HBOX(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_HBOX)
1719 #define LIVES_IS_VBOX(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_VBOX)
1720 #define LIVES_IS_COMBO(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_COMBO)
1721 #define LIVES_IS_ENTRY(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_ENTRY)
1722 #define LIVES_IS_MENU(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_MENU)
1723 #define LIVES_IS_MENU_BAR(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_MENU_BAR)
1724 #define LIVES_IS_MENU_ITEM(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_MENU_ITEM)
1725 #define LIVES_IS_TOOLBAR(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_TOOLBAR)
1726 #define LIVES_IS_FILE_CHOOSER(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_FILE_CHOOSER)
1727 #define LIVES_IS_SCALE(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SCALE)
1728 #define LIVES_IS_FRAME(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_FRAME)
1729 #define LIVES_IS_TOOL_ITEM(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_TOOL_ITEM)
1730 #define LIVES_IS_WINDOW(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_MAIN_WINDOW)
1731 #define LIVES_IS_DIALOG(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SUB_WINDOW || \
1732  static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_MESSAGE_DIALOG)
1733 #define LIVES_IS_PANED(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_PANED)
1734 #define LIVES_IS_TABLE(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_TABLE)
1735 #define LIVES_IS_IMAGE(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_IMAGE)
1736 #define LIVES_IS_PIXBUF(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_IMAGE)
1737 #define LIVES_IS_NOTEBOOK(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_NOTEBOOK)
1738 #define LIVES_IS_SPIN_BUTTON(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SPIN_BUTTON)
1739 #define LIVES_IS_SCROLLBAR(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SCROLLBAR)
1740 #define LIVES_IS_TREE_VIEW(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_TREE_VIEW)
1741 #define LIVES_IS_TEXT_VIEW(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_TEXT_VIEW)
1742 #define LIVES_IS_TEXT_BUFFER(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_TEXT_BUFFER)
1743 #define LIVES_IS_SCROLLED_WINDOW(a) (static_cast<LiVESObject *>(a)->get_type() == LIVES_WIDGET_TYPE_SCROLLED_WINDOW)
1744 
1745 
1746 bool evFilter::eventFilter(QObject *obj, QEvent *event) {
1747 
1748  // TODO - add motion-notify-event, leave-notify-event, button-release-event, focus_out_event
1749 
1750  // event->accept() to block ?
1751 
1752  // return true to block ?
1753 
1754  switch (event->type()) {
1755 
1756  case (QEvent::Shortcut): {
1757  QShortcutEvent *qevent = static_cast<QShortcutEvent *>(event);
1758  QKeySequence ks = qevent->key();
1759  LiVESObject *object = static_cast<LiVESObject *>(obj);
1760  object->activate_accel(ks);
1761  return false;
1762  }
1763 
1764  case (QEvent::Wheel): {
1765  QWheelEvent *qevent = static_cast<QWheelEvent *>(event);
1766  LiVESObject *object = static_cast<LiVESObject *>(obj);
1767  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1768  if (!(widget->get_events() & LIVES_SCROLL_MASK)) return true;
1769  if (!(widget->get_onetime_events_block() & LIVES_SCROLL_MASK)) {
1770  widget->remove_onetime_event_block(LIVES_SCROLL_MASK);
1771  event->accept();
1772  return true;
1773  }
1774  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_SCROLL_EVENT);
1775  LiVESXEventScroll *scrollevent = NULL;
1776  if (qevent->angleDelta().y() > 0) scrollevent->direction = LIVES_SCROLL_UP;
1777  else scrollevent->direction = LIVES_SCROLL_DOWN;
1778 
1779  scrollevent->state = QApplication::queryKeyboardModifiers();
1780 
1781  for (int i=0; i < accels.size(); i++) {
1782  LiVESScrollEventCallback *cb = (LiVESScrollEventCallback *)accels[i]->closure->function;
1783  bool ret = (*cb)(widget, scrollevent, accels[i]->closure->data);
1784  if (ret) return true;
1785  }
1786  }
1787 
1788  case (QEvent::Paint): {
1789  QPaintEvent *qevent = static_cast<QPaintEvent *>(event);
1790  LiVESObject *object = static_cast<LiVESObject *>(obj);
1791  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1792  if (!(widget->get_events() & LIVES_EXPOSURE_MASK)) return true;
1793  if (!(widget->get_onetime_events_block() & LIVES_EXPOSURE_MASK)) {
1794  widget->remove_onetime_event_block(LIVES_EXPOSURE_MASK);
1795  event->accept();
1796  return true;
1797  }
1798  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_EXPOSE_EVENT);
1799  LiVESXEventExpose *exposeevent = NULL;
1800  QRect qr = qevent->rect();
1801  exposeevent->area.x = qr.x();
1802  exposeevent->area.y = qr.y();
1803  exposeevent->area.width = qr.width();
1804  exposeevent->area.height = qr.height();
1805 
1806  exposeevent->count = 0;
1807 
1808  for (int i=0; i < accels.size(); i++) {
1809  LiVESExposeEventCallback *cb = (LiVESExposeEventCallback *)accels[i]->closure->function;
1810  bool ret = (*cb)(widget, exposeevent, accels[i]->closure->data);
1811  if (ret) return true;
1812  }
1813  }
1814 
1815  case (QEvent::Enter): {
1816  //QEnterEvent *qevent = static_cast<QEnterEvent *>(event);
1817  LiVESObject *object = static_cast<LiVESObject *>(obj);
1818  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1819  if (!(widget->get_events() & LIVES_ENTER_NOTIFY_MASK)) return true;
1820  if (!(widget->get_onetime_events_block() & LIVES_ENTER_NOTIFY_MASK)) {
1821  widget->remove_onetime_event_block(LIVES_ENTER_NOTIFY_MASK);
1822  event->accept();
1823  return true;
1824  }
1825  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_ENTER_EVENT);
1826  LiVESXEventCrossing *crossingevent = NULL;
1827 
1828  for (int i=0; i < accels.size(); i++) {
1829  LiVESEnterEventCallback *cb = (LiVESEnterEventCallback *)accels[i]->closure->function;
1830  bool ret = (*cb)(widget, crossingevent, accels[i]->closure->data);
1831  if (ret) return true;
1832  }
1833  }
1834 
1835  case (QEvent::MouseButtonPress): {
1836  QMouseEvent *qevent = static_cast<QMouseEvent *>(event);
1837  LiVESObject *object = static_cast<LiVESObject *>(obj);
1838  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1839  if (!(widget->get_events() & LIVES_BUTTON_PRESS_MASK)) return true;
1840  if (!(widget->get_onetime_events_block() & LIVES_BUTTON_PRESS_MASK)) {
1841  widget->remove_onetime_event_block(LIVES_BUTTON_PRESS_MASK);
1842  event->accept();
1843  return true;
1844  }
1845  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_BUTTON_PRESS_EVENT);
1846 
1847  LiVESXEventButton *buttonevent = NULL;
1848  if (qevent->button() == Qt::LeftButton) buttonevent->button = 1;
1849  if (qevent->button() == Qt::MidButton) buttonevent->button = 2;
1850  if (qevent->button() == Qt::RightButton) buttonevent->button = 3;
1851 
1852  buttonevent->type = LIVES_BUTTON_PRESS;
1853  buttonevent->time = qtime->elapsed();
1854 
1855  for (int i=0; i < accels.size(); i++) {
1856  LiVESButtonEventCallback *cb = (LiVESButtonEventCallback *)accels[i]->closure->function;
1857  bool ret = (*cb)(widget, buttonevent, accels[i]->closure->data);
1858  if (ret) return true;
1859  }
1860  }
1861 
1862  case (QEvent::MouseButtonDblClick): {
1863  QMouseEvent *qevent = static_cast<QMouseEvent *>(event);
1864  LiVESObject *object = static_cast<LiVESObject *>(obj);
1865  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1866  if (!(widget->get_events() & LIVES_BUTTON_PRESS_MASK)) return true;
1867  if (!(widget->get_onetime_events_block() & LIVES_BUTTON_PRESS_MASK)) {
1868  widget->remove_onetime_event_block(LIVES_BUTTON_PRESS_MASK);
1869  event->accept();
1870  return true;
1871  }
1872  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_BUTTON_PRESS_EVENT);
1873 
1874  LiVESXEventButton *buttonevent = NULL;
1875  if (qevent->button() == Qt::LeftButton) buttonevent->button = 1;
1876  if (qevent->button() == Qt::MidButton) buttonevent->button = 2;
1877  if (qevent->button() == Qt::RightButton) buttonevent->button = 3;
1878 
1879  buttonevent->type = LIVES_BUTTON2_PRESS;
1880 
1881  for (int i=0; i < accels.size(); i++) {
1882  LiVESButtonEventCallback *cb = (LiVESButtonEventCallback *)accels[i]->closure->function;
1883  bool ret = (*cb)(widget, buttonevent, accels[i]->closure->data);
1884  if (ret) return true;
1885  }
1886  }
1887 
1888  case (QEvent::Resize): {
1889  //QShowEvent *qevent = static_cast<QResizeEvent *>(event);
1890  LiVESObject *object = static_cast<LiVESObject *>(obj);
1891  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1892  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_CONFIGURE_EVENT);
1893  LiVESXEventConfigure *configureevent = NULL;
1894 
1895  for (int i=0; i < accels.size(); i++) {
1896  LiVESConfigureEventCallback *cb = (LiVESConfigureEventCallback *)accels[i]->closure->function;
1897  bool ret = (*cb)(widget, configureevent, accels[i]->closure->data);
1898  if (ret) return true;
1899  }
1900  }
1901 
1902  case (QEvent::Close): {
1903  //QCloseEvent *qevent = static_cast<QCloseEvent *>(event);
1904  LiVESObject *object = static_cast<LiVESObject *>(obj);
1905  LiVESWidget *widget = static_cast<LiVESWidget *>(object);
1906  QList<LiVESAccel *>accels = object->get_accels_for(LIVES_WIDGET_DELETE_EVENT);
1907  LiVESXEventDelete *deleteevent = NULL;
1908 
1909  for (int i=0; i < accels.size(); i++) {
1910  LiVESDeleteEventCallback *cb = (LiVESDeleteEventCallback *)accels[i]->closure->function;
1911  bool ret = (*cb)(widget, deleteevent, accels[i]->closure->data);
1912  if (ret) return true;
1913  }
1914  }
1915 
1916  default:
1917  return false;
1918 
1919  }
1920 
1921  return false; // continue
1922 }
1923 
1924 
1925 
1926 
1927 void LiVESWidget::update_stylesheet() {
1928  QWidget *qw = static_cast<QWidget *>(this);
1929  QString stylesheet;
1930  QString col;
1931 
1932  stylesheet = "QWidget#" + widgetName + " {color: ";
1933  col=make_col(fg_norm);
1934  stylesheet += col;
1935  stylesheet += "; background-color: ";
1936  col=make_col(bg_norm);
1937  stylesheet += col;
1938  stylesheet += "; selection-background-color: ";
1939  col=make_col(bg_sel);
1940  stylesheet += col;
1941  stylesheet += "; selection-color: ";
1942  col=make_col(fg_sel);
1943  stylesheet += col;
1944  stylesheet += " } ";
1945  stylesheet = "QWidget#" + widgetName + ":active {color: ";
1946  col=make_col(fg_act);
1947  stylesheet += col;
1948  stylesheet += "; background-color: ";
1949  col=make_col(bg_act);
1950  stylesheet += col;
1951  stylesheet += " } ";
1952  stylesheet = "QWidget#" + widgetName + ":[prelight=true] {color: ";
1953  col=make_col(fg_hover);
1954  stylesheet += col;
1955  stylesheet += "; background-color: ";
1956  col=make_col(bg_hover);
1957  stylesheet += col;
1958  stylesheet += " } ";
1959  stylesheet = "QWidget#" + widgetName + ":hover {color: ";
1960  col=make_col(fg_hover);
1961  stylesheet += col;
1962  stylesheet += "; background-color: ";
1963  col=make_col(bg_hover);
1964  stylesheet += col;
1965  stylesheet += " } ";
1966  stylesheet = "QWidget#" + widgetName + ":disabled {color: ";
1967  col=make_col(fg_insen);
1968  stylesheet += col;
1969  stylesheet += "; background-color: ";
1970  col=make_col(bg_insen);
1971  stylesheet += col;
1972  stylesheet += " } ";
1973 
1974  qw->setStyleSheet(stylesheet);
1975  qw->update();
1976 }
1977 
1978 
1979 
1980 void LiVESWidget::set_fg_color(LiVESWidgetState state, const LiVESWidgetColor *col) {
1981  switch (state) {
1982  case (LIVES_WIDGET_STATE_NORMAL):
1983  lives_widget_color_copy(fg_norm,col);
1984  break;
1985  case (LIVES_WIDGET_STATE_ACTIVE):
1986  lives_widget_color_copy(fg_act,col);
1987  break;
1988  case (LIVES_WIDGET_STATE_INSENSITIVE):
1989  lives_widget_color_copy(fg_insen,col);
1990  break;
1991  case (LIVES_WIDGET_STATE_PRELIGHT):
1992  lives_widget_color_copy(fg_hover,col);
1993  break;
1994  case (LIVES_WIDGET_STATE_SELECTED):
1995  lives_widget_color_copy(fg_sel,col);
1996  break;
1997  default:
1998  break;
1999  }
2000  update_stylesheet();
2001 }
2002 
2003 
2004 void LiVESWidget::set_bg_color(LiVESWidgetState state, const LiVESWidgetColor *col) {
2005  switch (state) {
2006  case (LIVES_WIDGET_STATE_NORMAL):
2007  lives_widget_color_copy(bg_norm,col);
2008  break;
2009  case (LIVES_WIDGET_STATE_ACTIVE):
2010  lives_widget_color_copy(bg_act,col);
2011  break;
2012  case (LIVES_WIDGET_STATE_INSENSITIVE):
2013  lives_widget_color_copy(bg_insen,col);
2014  break;
2015  case (LIVES_WIDGET_STATE_PRELIGHT):
2016  lives_widget_color_copy(bg_hover,col);
2017  break;
2018  case (LIVES_WIDGET_STATE_SELECTED):
2019  lives_widget_color_copy(bg_sel,col);
2020  break;
2021  default:
2022  break;
2023  }
2024  update_stylesheet();
2025 }
2026 
2027 
2028 void LiVESWidget::set_base_color(LiVESWidgetState state, const LiVESWidgetColor *col) {
2029  switch (state) {
2030  case (LIVES_WIDGET_STATE_NORMAL):
2031  lives_widget_color_copy(base_norm,col);
2032  break;
2033  case (LIVES_WIDGET_STATE_ACTIVE):
2034  lives_widget_color_copy(base_act,col);
2035  break;
2036  case (LIVES_WIDGET_STATE_INSENSITIVE):
2037  lives_widget_color_copy(base_insen,col);
2038  break;
2039  case (LIVES_WIDGET_STATE_PRELIGHT):
2040  lives_widget_color_copy(base_hover,col);
2041  break;
2042  case (LIVES_WIDGET_STATE_SELECTED):
2043  lives_widget_color_copy(base_sel,col);
2044  break;
2045  default:
2046  break;
2047  }
2048  update_stylesheet();
2049 }
2050 
2051 
2052 void LiVESWidget::set_text_color(LiVESWidgetState state, const LiVESWidgetColor *col) {
2053  switch (state) {
2054  case (LIVES_WIDGET_STATE_NORMAL):
2055  lives_widget_color_copy(text_norm,col);
2056  break;
2057  case (LIVES_WIDGET_STATE_ACTIVE):
2058  lives_widget_color_copy(text_act,col);
2059  break;
2060  case (LIVES_WIDGET_STATE_INSENSITIVE):
2061  lives_widget_color_copy(text_insen,col);
2062  break;
2063  case (LIVES_WIDGET_STATE_PRELIGHT):
2064  lives_widget_color_copy(text_hover,col);
2065  break;
2066  case (LIVES_WIDGET_STATE_SELECTED):
2067  lives_widget_color_copy(text_sel,col);
2068  break;
2069  default:
2070  break;
2071  }
2072  update_stylesheet();
2073 }
2074 
2075 
2076 LiVESWidgetColor *LiVESWidget::get_fg_color(LiVESWidgetState state) {
2077  switch (state) {
2078  case (LIVES_WIDGET_STATE_NORMAL):
2079  return fg_norm;
2080  break;
2081  case (LIVES_WIDGET_STATE_ACTIVE):
2082  return fg_act;
2083  break;
2084  case (LIVES_WIDGET_STATE_INSENSITIVE):
2085  return fg_insen;
2086  break;
2087  case (LIVES_WIDGET_STATE_PRELIGHT):
2088  return fg_hover;
2089  break;
2090  case (LIVES_WIDGET_STATE_SELECTED):
2091  return fg_sel;
2092  break;
2093  default:
2094  break;
2095  }
2096  return NULL;
2097 }
2098 
2099 
2100 LiVESWidgetColor *LiVESWidget::get_bg_color(LiVESWidgetState state) {
2101  switch (state) {
2102  case (LIVES_WIDGET_STATE_NORMAL):
2103  return bg_norm;
2104  break;
2105  case (LIVES_WIDGET_STATE_ACTIVE):
2106  return bg_act;
2107  break;
2108  case (LIVES_WIDGET_STATE_INSENSITIVE):
2109  return bg_insen;
2110  break;
2111  case (LIVES_WIDGET_STATE_PRELIGHT):
2112  return bg_hover;
2113  break;
2114  case (LIVES_WIDGET_STATE_SELECTED):
2115  return bg_sel;
2116  break;
2117  default:
2118  break;
2119  }
2120  return NULL;
2121 }
2122 
2123 
2124 ulong lives_signal_connect(LiVESObject *object, const char *signal_name, ulong funcptr, livespointer data) {
2125  ulong handler_id;
2126  handler_id=ulong_random();
2127 
2128  object->add_accel(handler_id, signal_name, funcptr, data);
2129 
2130  if (!strcmp(signal_name, LIVES_WIDGET_CLICKED_EVENT)) {
2131  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2132  SIGNAL(clicked()),
2133  static_cast<QObject *>(object),
2134  SLOT(cb_wrapper_clicked()));
2135  } else if (!strcmp(signal_name, LIVES_WIDGET_TOGGLED_EVENT)) {
2136  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2137  SIGNAL(toggled()),
2138  static_cast<QObject *>(object),
2139  SLOT(cb_wrapper_toggled()));
2140  } else if (!strcmp(signal_name, LIVES_WIDGET_CHANGED_EVENT)) {
2141  // for combo, entry, LiVESTreeSelection
2142  if (LIVES_IS_COMBO(object))
2143  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2144  SIGNAL(currentTextChanged()),
2145  static_cast<QObject *>(object),
2146  SLOT(cb_wrapper_changed()));
2147 
2148  else if (LIVES_IS_ENTRY(object))
2149  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2150  SIGNAL(textChanged()),
2151  static_cast<QObject *>(object),
2152  SLOT(cb_wrapper_changed()));
2153 
2154  else {
2155  QTreeWidget *qtw = dynamic_cast<QTreeWidget *>(object);
2156  if (qtw != NULL) {
2157  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2158  SIGNAL(itemSelectionChanged()),
2159  static_cast<QObject *>(object),
2160  SLOT(cb_wrapper_changed()));
2161 
2162  }
2163  }
2164  } else if (!strcmp(signal_name, LIVES_WIDGET_VALUE_CHANGED_EVENT)) {
2165  // for spinbutton, scrollbar
2166  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2167  SIGNAL(valueChanged()),
2168  static_cast<QObject *>(object),
2169  SLOT(cb_wrapper_value_changed()));
2170 
2171  } else if (!strcmp(signal_name, LIVES_WIDGET_SELECTION_CHANGED_EVENT)) {
2172  // for filedialog
2173  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2174  SIGNAL(currentChanged()),
2175  static_cast<QObject *>(object),
2176  SLOT(cb_wrapper_selection_changed()));
2177 
2178  } else if (!strcmp(signal_name, LIVES_WIDGET_CURRENT_FOLDER_CHANGED_EVENT)) {
2179  // for filedialog
2180  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2181  SIGNAL(currentUrlChanged()),
2182  static_cast<QObject *>(object),
2183  SLOT(cb_wrapper_current_folder_changed()));
2184 
2185  } else if (!strcmp(signal_name, LIVES_WIDGET_ACTIVATE_EVENT)) {
2186  // for menuitems (QAction)
2187  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2188  SIGNAL(triggered()),
2189  static_cast<QObject *>(object),
2190  SLOT(cb_wrapper_activate()));
2191 
2192  } else if (!strcmp(signal_name, LIVES_WIDGET_RESPONSE_EVENT)) {
2193  // for menuitems (QAction)
2194  (static_cast<QObject *>(object))->connect(static_cast<QObject *>(object),
2195  SIGNAL(finished()),
2196  static_cast<QObject *>(object),
2197  SLOT(cb_wrapper_response()));
2198 
2199  }
2200 
2201 
2202  return handler_id;
2203 }
2204 
2205 
2206 LIVES_INLINE void lives_widget_object_set_data(LiVESObject *widget, const char *prop, livespointer value) {
2207  QVariant v = qVariantFromValue((livespointer) value);
2208  widget->setProperty(prop, v);
2209 }
2210 
2211 
2212 LIVES_INLINE livespointer lives_widget_object_get_data(LiVESObject *widget, const char *prop) {
2213  QVariant v = widget->property(prop);
2214  return v.value<livespointer>();
2215 }
2216 
2217 
2218 
2219 
2220 #define lives_signal_connect_after(a,b,c,d) lives_signal_connect(a,b,c,d)
2221 
2222 
2223 
2224 void LiVESObject::add_accel(LiVESAccel *accel) {
2225  accels.push_back(accel);
2226 
2227  //QShortcut *shortcut = new QShortcut(accel->ks, dynamic_cast<QWidget *>(this));
2228  //accel->shortcut = shortcut;
2229 }
2230 
2231 
2232 void LiVESObject::add_accel(ulong handler_id, const char *signal_name, ulong funcptr, livespointer data) {
2233  LiVESAccel *accel = new LiVESAccel;
2234  accel->handler_id = handler_id;
2235  accel->signal_name = strdup(signal_name);
2236  LiVESClosure *cl = new LiVESClosure;
2237  cl->function = funcptr;
2238  cl->data = data;
2239  accel->closure = cl;
2240  add_accel(accel);
2241 }
2242 
2243 
2244 void LiVESObject::add_accel(const char *signal_name, LiVESAccelGroup *group, uint32_t key, LiVESXModifierType mod, LiVESAccelFlags flags) {
2245  LiVESAccel *accel = new LiVESAccel;
2246  accel->handler_id = 0;
2247  accel->signal_name = strdup(signal_name);
2248  accel->closure = NULL;
2249  accel->group = group;
2250  accel->ks = make_qkey_sequence(key, mod);
2251  accel->flags = flags;
2252  add_accel(accel);
2253 }
2254 
2255 
2256 boolean LiVESObject::remove_accel(LiVESAccel *accel) {
2257  QList<LiVESAccel *>::iterator it = accels.begin();
2258 
2259  while (it != accels.end()) {
2260  if (((LiVESAccel *)*it) == accel) {
2261  delete accel->shortcut;
2262  delete accel->signal_name;
2263  delete accel->closure;
2264  accels.erase(it);
2265  return TRUE;
2266  } else
2267  ++it;
2268  }
2269 
2270  return FALSE;
2271 }
2272 
2273 
2274 boolean LiVESObject::activate_accel(uint32_t key, LiVESXModifierType mod) {
2275  return activate_accel(make_qkey_sequence(key, mod));
2276 }
2277 
2278 
2279 boolean LiVESObject::activate_accel(QKeySequence ks) {
2280  for (int j=0; j < accel_groups.size(); j++) {
2281  QList<LiVESAccel *> ql = get_accels_for(accel_groups.at(j), ks);
2282  for (int i=0; i < ql.size(); i++) {
2283  LiVESAccel *accel = ql.at(i);
2284  if (accel->closure != NULL) {
2285  LiVESAccelCallback *cb = (LiVESAccelCallback *)accel->closure->function;
2286  uint32_t key = qkeysequence_get_key(ks);
2287  LiVESXModifierType mod = qkeysequence_get_mod(ks);
2288  (*cb)(accel->group, this, key, mod, accel->closure->data);
2289  } else {
2290  if (!strcmp(accel->signal_name, LIVES_WIDGET_CLICKED_EVENT)) {
2291  QAbstractButton *widget = dynamic_cast<QAbstractButton *>(this);
2292  if (widget != NULL) widget->click();
2293  }
2294 
2295  if (!strcmp(accel->signal_name, LIVES_WIDGET_TOGGLED_EVENT)) {
2296  QAbstractButton *widget = dynamic_cast<QAbstractButton *>(this);
2297  if (widget != NULL) widget->toggle();
2298  }
2299 
2300  }
2301  return TRUE;
2302  }
2303  }
2304  return FALSE;
2305 }
2306 
2307 
2308 
2309 void LiVESObject::remove_all_accels() {
2310  QList<LiVESAccel *>::iterator it = accels.begin();
2311  while (it != accels.end()) {
2312  remove_accel((LiVESAccel *)*it);
2313  }
2314 }
2315 
2316 
2317 QList<LiVESAccel *> LiVESObject::get_accels_for(ulong func, livespointer data) {
2318  QList<LiVESAccel *> ql;
2319  for (int i=0; i < accels.size(); i++) {
2320  if (accels[i]->closure == NULL) continue;
2321  if (accels[i]->closure->function == func && accels[i]->closure->data == data) ql.push_back(accels[i]);
2322  }
2323  return ql;
2324 }
2325 
2326 
2327 QList<LiVESAccel *> LiVESObject::get_accels_for(const char *signame) {
2328  QList<LiVESAccel *> ql;
2329  for (int i=0; i < accels.size(); i++) {
2330  if (accels[i]->signal_name == signame) ql.push_back(accels[i]);
2331  }
2332  return ql;
2333 }
2334 
2335 
2336 LiVESAccel *LiVESObject::get_accel_for(ulong handler_id) {
2337  for (int i=0; i < accels.size(); i++) {
2338  if (accels[i]->handler_id == handler_id) {
2339  return accels[i];
2340  }
2341  }
2342  return NULL;
2343 }
2344 
2345 
2346 void LiVESObject::block_signal(ulong handler_id) {
2347  LiVESAccel *accel = get_accel_for(handler_id);
2348  accel->blocked = true;
2349 }
2350 
2351 
2352 void LiVESObject::block_signals(const char *signame) {
2353  QList<LiVESAccel *>ql = get_accels_for(signame);
2354  for (int i=0; i < ql.size(); i++) {
2355  ql[i]->blocked = true;
2356  }
2357 }
2358 
2359 void LiVESObject::block_signals(ulong func, livespointer data) {
2360  QList<LiVESAccel *>ql = get_accels_for(func,data);
2361  for (int i=0; i < ql.size(); i++) {
2362  ql[i]->blocked = true;
2363  }
2364 }
2365 
2366 
2367 void LiVESObject::unblock_signal(ulong handler_id) {
2368  LiVESAccel *accel = get_accel_for(handler_id);
2369  accel->blocked = false;
2370 }
2371 
2372 
2373 void LiVESObject::unblock_signals(const char *signame) {
2374  QList<LiVESAccel *>ql = get_accels_for(signame);
2375  for (int i=0; i < ql.size(); i++) {
2376  ql[i]->blocked = false;
2377  }
2378 }
2379 
2380 
2381 void LiVESObject::unblock_signals(ulong func, livespointer data) {
2382  QList<LiVESAccel *>ql = get_accels_for(func,data);
2383  for (int i=0; i < ql.size(); i++) {
2384  ql[i]->blocked = false;
2385  }
2386 }
2387 
2388 
2389 void LiVESObject::disconnect_signal(ulong handler_id) {
2390  LiVESAccel *accel = get_accel_for(handler_id);
2391  remove_accel(accel);
2392 }
2393 
2394 
2395 QList<LiVESAccelGroup *> LiVESObject::get_accel_groups() {
2396  return accel_groups;
2397 }
2398 
2399 
2400 
2401 class LiVESBox : public LiVESWidget {};
2402 
2403 
2404 class LiVESHBox : public LiVESBox, public QHBoxLayout {
2405 public:
2406  LiVESHBox() {
2407  set_type(LIVES_WIDGET_TYPE_HBOX);
2408  }
2409 };
2410 
2411 
2412 class LiVESEventBox : public LiVESBox, public QHBoxLayout {
2413 public:
2414  LiVESEventBox() {
2415  set_type(LIVES_WIDGET_TYPE_EVENT_BOX);
2416  }
2417 };
2418 
2419 
2420 class LiVESDrawingArea : public LiVESBox, public QHBoxLayout {
2421 public:
2422  LiVESDrawingArea() {
2423  set_type(LIVES_WIDGET_TYPE_DRAWING_AREA);
2424  }
2425 };
2426 
2427 
2428 class LiVESVBox : public LiVESBox, public QVBoxLayout {
2429 public:
2430  LiVESVBox() {
2431  set_type(LIVES_WIDGET_TYPE_VBOX);
2432  }
2433 };
2434 
2435 
2436 typedef class LiVESRange LiVESRange;
2437 
2438 class LiVESAdjustment : public LiVESObject {
2439 
2440 public:
2441 
2442  LiVESAdjustment(double xval, double low, double upp, double step_i, double page_i, double page_s) :
2443  value(xval), lower(low), upper(upp), step_increment(step_i), page_increment(page_i), page_size(page_s), frozen(FALSE) {};
2444 
2445  void set_value(double newval);
2446  void set_lower(double newval);
2447 
2448  void set_upper(double newval);
2449  void set_step_increment(double newval);
2450  void set_page_increment(double newval);
2451  void set_page_size(double newval);
2452 
2453  void set_owner(LiVESWidget *widget) {
2454  owner = widget;
2455  }
2456 
2457  LiVESWidget *get_owner() {
2458  return owner;
2459  }
2460 
2461 
2462  double get_value() {
2463  return value;
2464  }
2465 
2466 
2467  double get_upper() {
2468  return upper;
2469  }
2470 
2471 
2472  double get_lower() {
2473  return lower;
2474  }
2475 
2476  double get_step_increment() {
2477  return step_increment;
2478  }
2479 
2480  double get_page_increment() {
2481  return page_increment;
2482  }
2483 
2484  double get_page_size() {
2485  return page_size;
2486  }
2487 
2488  void freeze() {
2489  frozen = true;
2490  }
2491 
2492  void thaw() {
2493  frozen = false;
2494  }
2495 
2496 private:
2497  double value;
2498  double lower;
2499  double upper;
2500  double step_increment;
2501  double page_increment;
2502  double page_size;
2503  boolean frozen;
2504 
2505  LiVESWidget *owner;
2506 
2507 };
2508 
2509 
2510 LIVES_INLINE QString qmake_mnemonic(QString qlabel) {
2511  qlabel = qlabel.replace('&',"&&");
2512  qlabel = qlabel.replace('_','&');
2513  return qlabel;
2514 }
2515 
2516 
2517 LIVES_INLINE QString qmake_underline(QString qlabel) {
2518  qlabel = qlabel.replace('&','_');
2519  qlabel = qlabel.replace("__","&");
2520  return qlabel;
2521 }
2522 
2523 
2524 class LiVESButtonBase : public LiVESWidget {
2525 public:
2526  LiVESButtonBase() {
2527  init();
2528  }
2529 
2530  LiVESButtonBase(QString qs) {
2531  init();
2532  }
2533 
2534  void set_use_underline(bool use) {
2535  QAbstractButton *qab = dynamic_cast<QAbstractButton *>(this);
2536  if (qab != NULL) {
2537  if (use && !use_underline) {
2538  // alter label
2539  qab->setText(qmake_mnemonic(qab->text()));
2540  } else if (!use && use_underline) {
2541  qab->setText(qmake_underline(qab->text()));
2542  }
2543  }
2544  use_underline = use;
2545  }
2546 
2547  bool get_use_underline() {
2548  return use_underline;
2549  }
2550 
2551 private:
2552  bool use_underline;
2553 
2554  void init() {
2555  use_underline = false;
2556  }
2557 
2558 };
2559 
2560 
2561 
2562 class LiVESToggleButton : public LiVESButtonBase, public QCheckBox {};
2563 
2564 
2565 
2566 
2567 class LiVESButton : public LiVESButtonBase, public QPushButton {
2568 public:
2569 
2570  LiVESButton() {
2571  init();
2572  }
2573 
2574  LiVESButton(QString qs) {
2575  init();
2576  }
2577 
2578  LiVESWidget *get_layout() {
2579  if (layout == NULL) {
2580  layout = new LiVESVBox;
2581  (static_cast<QPushButton *>(this))->setLayout(dynamic_cast<QLayout *>(layout));
2582  if ((static_cast<LiVESWidget *>(this))->isVisible()) layout->setVisible(true);
2583  add_child(layout);
2584  }
2585  return layout;
2586  }
2587 
2588 private:
2589  LiVESWidget *layout;
2590  void init() {
2591  set_type(LIVES_WIDGET_TYPE_BUTTON);
2592  }
2593 
2594 };
2595 
2596 
2597 
2598 
2599 class LiVESSpinButton : public LiVESButtonBase, public QDoubleSpinBox {
2600 public:
2601 
2602  LiVESSpinButton(LiVESAdjustment *xadj, double climb_rate, uint32_t digits) : adj(xadj) {
2603  init();
2604 
2605  adj->set_owner(this);
2606 
2607  setDecimals(digits);
2608  setSingleStep(climb_rate);
2609 
2610  setValue(adj->get_value());
2611  setMinimum(adj->get_lower());
2612  setMaximum(adj->get_upper());
2613 
2614  }
2615 
2616  LiVESAdjustment *get_adj() {
2617  return adj;
2618  }
2619 
2620  void valueChanged(double value) {
2621  adj->freeze();
2622  adj->set_value(value);
2623  adj->thaw();
2624  }
2625 
2626 private:
2627  LiVESAdjustment *adj;
2628 
2629  void init() {
2630  set_type(LIVES_WIDGET_TYPE_SPIN_BUTTON);
2631  }
2632 
2633 };
2634 
2635 
2636 
2637 
2638 class LiVESRadioButton : public LiVESButtonBase, public QRadioButton {
2639 public:
2640  LiVESRadioButton() {
2641  init();
2642  }
2643 
2644  LiVESRadioButton(QString qs) {
2645  init();
2646  }
2647 
2648  void set_group(LiVESSList *xlist) {
2649  slist = xlist;
2650  }
2651 
2652  LiVESSList *get_list() {
2653  return slist;
2654  }
2655 
2656 
2657  ~LiVESRadioButton() {
2658  QButtonGroup *qbg = (QButtonGroup *)lives_slist_nth_data(slist, 0);
2659  QList<QAbstractButton *> ql = qbg->buttons();
2660  if (ql.size() == 1) lives_slist_remove(slist, (livesconstpointer)qbg);
2661  }
2662 
2663 private:
2664  LiVESSList *slist;
2665 
2666  void init() {
2667  //setCheckable(true);
2668  set_type(LIVES_WIDGET_TYPE_RADIO_BUTTON);
2669  }
2670 
2671 };
2672 
2673 
2674 
2675 class LiVESCheckButton : public LiVESToggleButton {
2676 public:
2677 
2678  LiVESCheckButton() {
2679  init();
2680  }
2681 
2682  LiVESCheckButton(QString qs) {
2683  init();
2684  }
2685 
2686 private:
2687  void init() {
2688  set_type(LIVES_WIDGET_TYPE_CHECK_BUTTON);
2689  }
2690 
2691 };
2692 
2693 
2694 
2695 class LiVESButtonBox : public LiVESWidget, public QDialogButtonBox {
2696 public:
2697  LiVESButtonBox() {
2698  set_type(LIVES_WIDGET_TYPE_BUTTON_BOX);
2699  }
2700 
2701 };
2702 
2703 
2704 
2705 class LiVESMenuBar : public LiVESWidget, public QMenuBar {
2706 public:
2707  LiVESMenuBar() {
2708  set_type(LIVES_WIDGET_TYPE_MENU_BAR);
2709  }
2710 
2711 
2712  void reorder_child(LiVESWidget *child, int pos) {
2713  LiVESList *children = get_children();
2714  LiVESList *new_children;
2715  QMenuBar *qmenu = static_cast<QMenuBar *>(this);
2716 
2717  for (int i = 0; children != NULL; i++) {
2718  if (i==pos) lives_list_append(new_children,child);
2719  else if (children->data != (livespointer)child) lives_list_append(new_children,children->data);
2720  qmenu->removeAction((QAction *)(children->data));
2721  children = children->next;
2722  }
2723 
2724  children = new_children;
2725 
2726  for (int i = 0; new_children != NULL; i++) {
2727  qmenu->addAction((QAction *)(new_children->data));
2728  new_children = new_children->next;
2729  }
2730 
2731  set_children(new_children);
2732  }
2733 
2734 
2735 
2736 };
2737 
2738 
2739 
2740 
2741 class LiVESMenu : public LiVESWidget, public QMenu {
2742 public:
2743  LiVESMenu() {
2744  set_type(LIVES_WIDGET_TYPE_MENU);
2745  }
2746 
2747  void reorder_child(LiVESWidget *child, int pos) {
2748  LiVESList *children = get_children();
2749  LiVESList *new_children;
2750  QMenu *qmenu = static_cast<QMenu *>(this);
2751 
2752  for (int i = 0; children != NULL; i++) {
2753  if (i==pos) lives_list_append(new_children,child);
2754  else if (children->data != (livespointer)child) lives_list_append(new_children,children->data);
2755  qmenu->removeAction((QAction *)(children->data));
2756  children = children->next;
2757  }
2758 
2759  children = new_children;
2760 
2761  for (int i = 0; new_children != NULL; i++) {
2762  qmenu->addAction((QAction *)(new_children->data));
2763  new_children = new_children->next;
2764  }
2765 
2766  set_children(new_children);
2767  }
2768 
2769 };
2770 
2771 
2772 class LiVESTornOffMenu : public LiVESMenu {
2773 public:
2774  LiVESTornOffMenu(LiVESMenu *menu) {
2775  QWidget *qmenu = static_cast<QWidget *>(static_cast<QMenu *>(menu));
2776  QWidget *parentWidget = qmenu->parentWidget();
2777  QWidget *qwidget = (static_cast<QWidget *>(static_cast<QMenu *>(this)));
2778  qwidget->setParent(parentWidget, Qt::Window | Qt::Tool);
2779  qwidget->setAttribute(Qt::WA_DeleteOnClose, true);
2780  qwidget->setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true);
2781  qwidget->setWindowTitle(qmenu->windowTitle());
2782  qwidget->setEnabled(qmenu->isEnabled());
2783 
2784  QList<QAction *> items = qmenu->actions();
2785  for (int i = 0; i < items.count(); i++)
2786  qwidget->addAction(items.at(i));
2787 
2788  set_parent(menu->get_parent());
2789 
2790  if (qmenu->isVisible()) {
2791  qmenu->hide();
2792  qwidget->setVisible(true);
2793  }
2794 
2795  }
2796 };
2797 
2798 
2799 
2800 
2801 
2802 class LiVESMenuItem : public LiVESWidget, public QAction {
2803 public:
2804  LiVESMenuItem(LiVESWidget *parent) : QAction(static_cast<QObject *>(static_cast<LiVESObject *>(parent))) {
2805  set_type(LIVES_WIDGET_TYPE_MENU_ITEM);
2806  }
2807 
2808  LiVESMenuItem(const QString &text, LiVESWidget *parent) : QAction(text, static_cast<QObject *>(static_cast<LiVESObject *>(parent))) {
2809  set_type(LIVES_WIDGET_TYPE_MENU_ITEM);
2810  this->setText(text);
2811  }
2812 
2813 
2814 
2815 };
2816 
2817 
2818 
2819 class LiVESToolItem : public LiVESWidget, public QHBoxLayout {
2820 public:
2821  LiVESToolItem() {
2822  init();
2823  }
2824 
2825  LiVESWidget *get_layout() {
2826  if (layout == NULL) {
2827  layout = new LiVESVBox;
2828  (static_cast<QHBoxLayout *>(this))->addLayout(dynamic_cast<QLayout *>(layout));
2829  if ((static_cast<LiVESWidget *>(this))->isVisible()) layout->setVisible(true);
2830  add_child(layout);
2831  }
2832  return layout;
2833  }
2834 
2835 private:
2836  LiVESWidget *layout;
2837 
2838  void init() {
2839  set_type(LIVES_WIDGET_TYPE_TOOL_ITEM);
2840  }
2841 };
2842 
2843 
2844 
2845 
2846 typedef LiVESMenuItem LiVESImageMenuItem;
2847 
2848 
2849 
2850 class LiVESMenuToolButton : public LiVESToolItem, public QWidgetAction {
2851 public:
2852 
2853  LiVESMenuToolButton(const QString &text, LiVESWidget *parent, LiVESWidget *icon) :
2854  QWidgetAction(static_cast<QObject *>(static_cast<LiVESObject *>(parent))) {
2855  QPushButton *qbutton = new QPushButton(text);
2856  set_type(LIVES_WIDGET_TYPE_MENU_TOOL_BUTTON);
2857  setDefaultWidget(qbutton);
2858  //setIcon(qicon);
2859  }
2860 
2861 };
2862 
2863 
2864 
2865 
2866 class LiVESCheckMenuItem : public LiVESWidget, public QAction {
2867 public:
2868  LiVESCheckMenuItem(LiVESWidget *parent) : QAction(static_cast<QObject *>(static_cast<LiVESObject *>(parent))) {
2869  }
2870 
2871  LiVESCheckMenuItem(const QString &text, LiVESWidget *parent) : QAction(text, static_cast<QObject *>(static_cast<LiVESObject *>(parent))) {
2872  setText(text);
2873  }
2874 
2875 private:
2876  void init() {
2877  set_type(LIVES_WIDGET_TYPE_CHECK_MENU_ITEM);
2878  setCheckable(true);
2879  }
2880 
2881 
2882 };
2883 
2884 
2885 class LiVESRadioMenuItem : public LiVESMenuItem {
2886 public:
2887 
2888  LiVESRadioMenuItem(LiVESWidget *parent) : LiVESMenuItem(parent) {
2889  init();
2890  }
2891 
2892  LiVESRadioMenuItem(const QString &text, LiVESWidget *parent) : LiVESMenuItem(text, parent) {
2893  init();
2894  setText(text);
2895  }
2896 
2897 
2898  void set_group(LiVESSList *xlist) {
2899  slist = xlist;
2900  }
2901 
2902  LiVESSList *get_list() {
2903  return slist;
2904  }
2905 
2906 
2907  ~LiVESRadioMenuItem() {
2908  QActionGroup *qag = const_cast<QActionGroup *>(static_cast<const QActionGroup *>(lives_slist_nth_data(slist, 0)));
2909  QList<QAction *> ql = qag->actions();
2910  if (ql.size() == 1) lives_slist_remove(slist, (livesconstpointer)qag);
2911  }
2912 
2913 private:
2914  LiVESSList *slist;
2915 
2916  void init() {
2917  setCheckable(true);
2918  set_type(LIVES_WIDGET_TYPE_RADIO_MENU_ITEM);
2919  }
2920 };
2921 
2922 
2923 
2924 
2925 class LiVESCombo : public LiVESWidget, public QComboBox {
2926 public:
2927  LiVESCombo() {
2928  set_type(LIVES_WIDGET_TYPE_COMBO);
2929  }
2930 };
2931 
2932 
2933 class LiVESHSeparator : public LiVESWidget, public QHBoxLayout {
2934 public:
2935  LiVESHSeparator() {
2936  QFrame *line = new QFrame();
2937  line->setFrameShape(QFrame::HLine);
2938  line->setFrameShadow(QFrame::Sunken);
2939  addWidget(line);
2940  set_type(LIVES_WIDGET_TYPE_HSEPARATOR);
2941  }
2942 };
2943 
2944 
2945 
2946 class LiVESVSeparator : public LiVESWidget, public QVBoxLayout {
2947 public:
2948  LiVESVSeparator() {
2949  QFrame *line = new QFrame();
2950  line->setFrameShape(QFrame::VLine);
2951  line->setFrameShadow(QFrame::Sunken);
2952  addWidget(line);
2953  set_type(LIVES_WIDGET_TYPE_VSEPARATOR);
2954  }
2955 };
2956 
2957 
2958 
2959 class LiVESTextBuffer : public LiVESWidget, public QTextDocument {
2960 public:
2961 
2962  LiVESTextBuffer() {
2963  insert = QTextCursor(this);
2964  }
2965 
2966  QTextCursor get_cursor() {
2967  return insert;
2968  }
2969 
2970 private:
2971  QTextCursor insert;
2972 
2973 };
2974 
2975 
2976 
2977 class LiVESTextView : public LiVESWidget, public QTextEdit {
2978 public:
2979 
2980  LiVESTextView() {
2981  buff = new LiVESTextBuffer();
2982  }
2983 
2984 
2985  LiVESTextView(LiVESTextBuffer *xbuff) : QTextEdit(), buff(xbuff) {
2986  set_type(LIVES_WIDGET_TYPE_TEXT_VIEW);
2987  setDocument(buff);
2988  }
2989 
2990  ~LiVESTextView() {
2991  delete buff;
2992  }
2993 
2994 
2995  LiVESTextBuffer *get_buffer() {
2996  return buff;
2997  }
2998 
2999 private:
3000  LiVESTextBuffer *buff;
3001 
3002  void init() {
3003  set_type(LIVES_WIDGET_TYPE_TEXT_VIEW);
3004  setDocument(buff);
3005  }
3006 
3007 
3008 };
3009 
3010 
3011 
3012 class LiVESTextMark : public LiVESObject, public QTextCursor {
3013 public:
3014 
3015  LiVESTextMark(LiVESTextBuffer *tbuff, const char *mark_name,
3016  int where, boolean left_gravity) : QTextCursor(tbuff), name(mark_name), lgrav(left_gravity) {
3017  (static_cast<QTextCursor *>(this))->setPosition(where);
3018  }
3019 
3020  ~LiVESTextMark() {
3021  delete name;
3022  }
3023 
3024  QString get_name() {
3025  return name;
3026  }
3027 
3028 private:
3029  const char *name;
3030  boolean lgrav;
3031 
3032 };
3033 
3034 
3035 
3036 class LiVESRange : public LiVESWidget {
3037  Q_OBJECT
3038 
3039 public:
3040  LiVESRange(LiVESAdjustment *adj) {
3041  init(adj);
3042  }
3043 
3044  virtual void init(LiVESAdjustment *adj) {}
3045 
3046  LiVESAdjustment *get_adj() {
3047  return adj;
3048  }
3049 
3050 public slots:
3051  void valueChanged(int value) {
3052  adj->freeze();
3053  adj->set_value(value);
3054  adj->thaw();
3055  }
3056 
3057 private:
3058  LiVESAdjustment *adj;
3059 
3060 };
3061 
3062 
3063 class LiVESScale : public LiVESRange, public QSlider {
3064  // TODO - add a label
3065 public:
3066  LiVESScale(Qt::Orientation, LiVESAdjustment *xadj) : LiVESRange(xadj) {
3067  set_type(LIVES_WIDGET_TYPE_SCALE);
3068  }
3069 
3070  void init(LiVESAdjustment *adj) {
3071  adj->set_owner(this);
3072  setMinimum(adj->get_lower());
3073  setMaximum(adj->get_upper());
3074  setValue(adj->get_value());
3075  setSingleStep(adj->get_step_increment());
3076  setPageStep(adj->get_page_increment());
3077  }
3078 };
3079 
3080 
3081 class LiVESScrollbar : public LiVESRange, public QScrollBar {
3082 public:
3083  LiVESScrollbar(Qt::Orientation, LiVESAdjustment *xadj) : LiVESRange(xadj) {
3084  set_type(LIVES_WIDGET_TYPE_SCROLLBAR);
3085  }
3086 
3087  void init(LiVESAdjustment *adj) {
3088  adj->set_owner(this);
3089  setMinimum(adj->get_lower());
3090  setMaximum(adj->get_upper());
3091  setValue(adj->get_value());
3092  setSingleStep(adj->get_step_increment());
3093  setPageStep(adj->get_page_increment());
3094  }
3095 
3096 };
3097 
3098 typedef LiVESScrollbar LiVESHScrollbar;
3099 
3100 
3101 class LiVESEntry : public LiVESWidget, public QLineEdit {
3102 public:
3103  LiVESEntry() {
3104  set_type(LIVES_WIDGET_TYPE_ENTRY);
3105  }
3106 };
3107 
3108 
3109 class LiVESProgressBar : public LiVESWidget, public QProgressBar {
3110 public:
3111  LiVESProgressBar() {
3112  set_type(LIVES_WIDGET_TYPE_PROGRESS_BAR);
3113  }
3114 };
3115 
3116 
3117 class LiVESPaned : public LiVESWidget, public QSplitter {
3118 public:
3119 
3120  LiVESPaned() {
3121  set_type(LIVES_WIDGET_TYPE_PANED);
3122  }
3123 };
3124 
3125 
3126 class LiVESLabel : public LiVESWidget, public QLabel {
3127 public:
3128  LiVESLabel(QString qstring) {
3129  set_type(LIVES_WIDGET_TYPE_LABEL);
3130  }
3131 
3132  LiVESWidget *get_mnemonic_widget() {
3133  return mnemonicw;
3134  }
3135 
3136  void set_mnemonic_widget(LiVESWidget *widget) {
3137  mnemonicw = widget;
3138  }
3139 
3140  void set_owner(LiVESWidget *xowner) {
3141  owner = xowner;
3142  }
3143 
3144  LiVESWidget *get_owner() {
3145  return owner;
3146  }
3147 
3148  void set_text(QString text) {
3149  // if we have an owner, update owner text
3150  // TODO
3151  }
3152 
3153 
3154 private:
3155  LiVESWidget *mnemonicw;
3156  LiVESWidget *owner; // TODO
3157 };
3158 
3159 
3160 class LiVESRuler : public LiVESWidget, public QSlider {
3161 public:
3162  LiVESRuler() {
3163  set_type(LIVES_WIDGET_TYPE_RULER);
3164  }
3165 };
3166 
3167 
3168 
3169 
3170 class LiVESScrolledWindow : public LiVESWidget, public QScrollArea {
3171 public:
3172  LiVESScrolledWindow(LiVESAdjustment *xhadj, LiVESAdjustment *xvadj) : hadj(xhadj), vadj(xvadj) {
3173  set_type(LIVES_WIDGET_TYPE_SCROLLED_WINDOW);
3174  hadj->set_owner(this);
3175  vadj->set_owner(this);
3176 
3177  QScrollBar *hs = horizontalScrollBar();
3178  hs->setMinimum(hadj->get_lower());
3179  hs->setMaximum(hadj->get_upper());
3180  hs->setValue(hadj->get_value());
3181  hs->setSingleStep(hadj->get_step_increment());
3182  hs->setPageStep(hadj->get_page_increment());
3183 
3184  QScrollBar *vs = verticalScrollBar();
3185  vs->setMinimum(vadj->get_lower());
3186  vs->setMaximum(vadj->get_upper());
3187  vs->setValue(vadj->get_value());
3188  vs->setSingleStep(vadj->get_step_increment());
3189  vs->setPageStep(vadj->get_page_increment());
3190 
3191  }
3192 
3193  LiVESAdjustment *get_hadj() {
3194  return hadj;
3195  }
3196 
3197  LiVESAdjustment *get_vadj() {
3198  return vadj;
3199  }
3200 
3201 private:
3202  LiVESAdjustment *hadj;
3203  LiVESAdjustment *vadj;
3204 
3205 };
3206 
3207 
3208 
3209 
3210 
3211 class LiVESToolButton : public LiVESToolItem, public QToolButton {
3212 public:
3213 
3214  LiVESToolButton(LiVESWidget *icon_widget, const char *label) {
3215  set_type(LIVES_WIDGET_TYPE_TOOL_BUTTON);
3216  set_icon_widget(icon_widget);
3217  layout = new LiVESVBox;
3218  QBoxLayout *ql = static_cast<QVBoxLayout *>(layout);
3219  ql->setParent(static_cast<QToolButton *>(this));
3220  add_child(layout);
3221  if (label != NULL) {
3222  LiVESWidget *widget = new LiVESLabel(label);
3223  layout->add_child(widget);
3224  label_widget = dynamic_cast<LiVESLabel *>(widget);
3225  (static_cast<QBoxLayout *>(layout))->addWidget(static_cast<QLabel *>(label_widget));
3226  } else label_widget = NULL;
3227  }
3228 
3229 
3230  void set_icon_widget(LiVESWidget *widget) {
3231  if (icon_widget != NULL) remove_child(icon_widget);
3232  icon_widget = NULL;
3233  QImage *qim = NULL;
3234  if (widget != NULL) qim = dynamic_cast<QImage *>(widget);
3235  if (qim) {
3236  QPixmap *qpx = new QPixmap();
3237  qpx->convertFromImage(*qim);
3238  QIcon *qi = new QIcon(*qpx);
3239  setIcon(*qi);
3240  setIconSize(LIVES_ICON_SIZE_SMALL_TOOLBAR);
3241  icon_widget = widget;
3242  add_child(widget);
3243  }
3244  }
3245 
3246 
3247  void set_label_widget(LiVESWidget *widget) {
3248  if (label_widget != NULL) {
3249  layout->remove_child(static_cast<LiVESWidget *>(label_widget));
3250  layout->removeWidget(static_cast<LiVESWidget *>(label_widget));
3251  }
3252  if (widget != NULL) {
3253  layout->addWidget(widget);
3254  label_widget = dynamic_cast<LiVESLabel *>(widget);
3255  layout->add_child(label_widget);
3256  label_widget->set_owner(this);
3257  } else label_widget = NULL;
3258  }
3259 
3260 
3261  void set_use_underline(bool use) {
3262  QAbstractButton *qab = dynamic_cast<QAbstractButton *>(this);
3263  if (qab != NULL) {
3264  if (use && !use_underline) {
3265  // alter label
3266  qab->setText(qmake_mnemonic(qab->text()));
3267  } else if (!use && use_underline) {
3268  qab->setText(qmake_underline(qab->text()));
3269  }
3270  }
3271  use_underline = use;
3272  }
3273 
3274  bool get_use_underline() {
3275  return use_underline;
3276  }
3277 
3278 private:
3279  bool use_underline;
3280 
3281  void init() {
3282  use_underline = false;
3283  }
3284 
3285 private:
3286  LiVESWidget *icon_widget;
3287  LiVESLabel *label_widget;
3288  LiVESVBox *layout;
3289 
3290 };
3291 
3292 
3293 
3294 
3295 
3296 
3297 
3298 typedef class LiVESWindow LiVESWindow;
3299 
3300 class LiVESAccelGroup {
3301 public:
3302  void add_all_accelerators(LiVESObject *window);
3303  void add_widget(LiVESObject *window);
3304  void remove_all_accelerators(LiVESObject *window);
3305  void remove_widget(LiVESObject *window);
3306 
3307  void connect(uint32_t key, LiVESXModifierType mod, LiVESAccelFlags flags, LiVESWidgetClosure *closure);
3308  void disconnect(LiVESWidgetClosure *closure);
3309 
3310  ~LiVESAccelGroup();
3311 
3312 private:
3313  QList<LiVESObject *>widgets;
3314  QList<LiVESAccel *>accels;
3315 
3316 
3317 };
3318 
3319 
3320 
3321 
3322 void LiVESObject::add_accel_group(LiVESAccelGroup *group) {
3323  accel_groups.push_back(group);
3324  group->add_all_accelerators(this);
3325  group->add_widget(this);
3326 }
3327 
3328 
3329 
3330 boolean LiVESObject::remove_accel_group(LiVESAccelGroup *group) {
3331  if (accel_groups.removeAll(group) > 0) {
3332  group->remove_all_accelerators(this);
3333  group->remove_widget(this);
3334  return TRUE;
3335  }
3336  return FALSE;
3337 }
3338 
3339 
3340 
3341 boolean LiVESObject::remove_accels(LiVESAccelGroup *group, uint32_t key, LiVESXModifierType mods) {
3342  bool ret = false;
3343  QKeySequence ks = make_qkey_sequence(key, mods);
3344 
3345  QList<LiVESAccel *>::iterator it = accels.begin();
3346  while (it != accels.end()) {
3347  if (((LiVESAccel *)*it)->group == group && ((LiVESAccel *)*it)->ks == ks) {
3348  remove_accel((LiVESAccel *)*it);
3349  ret = true;
3350  } else
3351  ++it;
3352  }
3353  return ret;
3354 }
3355 
3356 
3357 QList<LiVESAccel *> LiVESObject::get_accels_for(LiVESAccelGroup *group, QKeySequence ks) {
3358  QList<LiVESAccel *> ql;
3359  for (int i=0; i < accels.size(); i++) {
3360  if (accels[i]->group == group && accels[i]->ks == ks) ql.push_back(accels[i]);
3361  }
3362  return ql;
3363 }
3364 
3365 
3366 
3367 class LiVESWindow : public LiVESWidget {};
3368 
3369 typedef int LiVESWindowPosition;
3370 #define LIVES_WIN_POS_DEFAULT 0
3371 #define LIVES_WIN_POS_CENTER_ALWAYS 1
3372 
3373 
3374 class LiVESMainWindow : public LiVESWindow, public QMainWindow {
3375 public:
3376  LiVESMainWindow() {
3377  set_type(LIVES_WIDGET_TYPE_MAIN_WINDOW);
3378  set_position(LIVES_WIN_POS_DEFAULT);
3379  }
3380 
3381  LiVESWidget *get_layout() {
3382  if (layout == NULL) {
3383  layout = new LiVESVBox;
3384  (static_cast<QMainWindow *>(this))->setLayout(dynamic_cast<QLayout *>(layout));
3385  if ((static_cast<LiVESWidget *>(this))->isVisible()) layout->setVisible(true);
3386  add_child(layout);
3387  }
3388  return layout;
3389  }
3390 
3391  void set_position(LiVESWindowPosition xpos) {
3392  pos = xpos;
3393  }
3394 
3395  LiVESWindowPosition get_position() {
3396  return pos;
3397  }
3398 
3399 
3400 private:
3401  LiVESWidget *layout;
3402  LiVESWindowPosition pos;
3403 
3404 };
3405 
3406 
3407 
3408 void LiVESAccelGroup::add_all_accelerators(LiVESObject *object) {
3409  for (int i=0; i < accels.size(); i++) {
3410  object->add_accel(accels.at(i));
3411  }
3412 }
3413 
3414 void LiVESAccelGroup::add_widget(LiVESObject *window) {
3415  widgets.push_back(window);
3416 }
3417 
3418 
3419 void LiVESAccelGroup::remove_all_accelerators(LiVESObject *object) {
3420  while (accels.size() > 0) {
3421  object->remove_accel(accels.at(0));
3422  }
3423 }
3424 
3425 
3426 void LiVESAccelGroup::remove_widget(LiVESObject *window) {
3427  widgets.removeAll(window);
3428 }
3429 
3430 
3431 LiVESAccelGroup::~LiVESAccelGroup() {
3432  while (widgets.size() > 0) {
3433  remove_all_accelerators(widgets.at(0));
3434  }
3435 }
3436 
3437 
3438 class LiVESVLayout: public LiVESWidget, public QVBoxLayout {};
3439 
3440 class LiVESDialog : public LiVESWindow, public QDialog {
3441 public:
3442  LiVESDialog() {
3443  QDialog *qd = static_cast<QDialog *>(this);
3444  QVBoxLayout *layout = new QVBoxLayout;
3445  layout->setMargin(0);
3446  qd->setLayout(layout);
3447 
3448  contentArea = new LiVESVLayout();
3449  QVBoxLayout *ca = dynamic_cast<QVBoxLayout *>(contentArea);
3450  ca->setMargin(0);
3451  layout->insertLayout(0, ca);
3452 
3453  actionArea = new LiVESButtonBox;
3454  QDialogButtonBox *bb = dynamic_cast<QDialogButtonBox *>(actionArea);
3455  bb->setContentsMargins(0, 0, 0, 0);
3456  layout->addWidget(bb);
3457 
3458  set_type(LIVES_WIDGET_TYPE_DIALOG);
3459 
3460  add_child(actionArea);
3461  add_child(contentArea);
3462 
3463  }
3464 
3465  LiVESWidget *get_content_area() {
3466  return contentArea;
3467  }
3468 
3469  LiVESWidget *get_action_area() {
3470  return actionArea;
3471  }
3472 
3473  LiVESWidget *get_layout() {
3474  if (layout == NULL) {
3475  layout = new LiVESVBox;
3476  (static_cast<QDialog *>(this))->setLayout(dynamic_cast<QLayout *>(layout));
3477  if ((static_cast<LiVESWidget *>(this))->isVisible()) layout->setVisible(true);
3478  add_child(layout);
3479  }
3480  return layout;
3481  }
3482 
3483 private:
3484  LiVESWidget *layout;
3485  LiVESWidget *contentArea;
3486  LiVESWidget *actionArea;
3487 };
3488 
3489 
3490 typedef int LiVESDialogFlags;
3491 typedef QMessageBox::Icon LiVESMessageType;
3492 
3493 #define LIVES_MESSAGE_INFO QMessageBox::Information
3494 #define LIVES_MESSAGE_WARNING QMessageBox::Warning
3495 #define LIVES_MESSAGE_QUESTION QMessageBox::Question
3496 #define LIVES_MESSAGE_ERROR QMessageBox::Warning
3497 #define LIVES_MESSAGE_OTHER QMessageBox::NoIcon
3498 
3499 typedef int LiVESButtonsType;
3500 #define LIVES_BUTTONS_NONE 0
3501 
3502 class LiVESMessageDialog : public LiVESWindow, public QMessageBox {
3503 public:
3504  LiVESMessageDialog() {
3505  QMessageBox *qd = static_cast<QMessageBox *>(this);
3506  QVBoxLayout *layout = new QVBoxLayout;
3507  layout->setMargin(0);
3508  qd->setLayout(layout);
3509 
3510  contentArea = new LiVESVLayout();
3511  QVBoxLayout *ca = dynamic_cast<QVBoxLayout *>(contentArea);
3512  ca->setMargin(0);
3513  layout->insertLayout(0, ca);
3514 
3515  actionArea = new LiVESButtonBox;
3516  QDialogButtonBox *bb = dynamic_cast<QDialogButtonBox *>(actionArea);
3517  bb->setContentsMargins(0, 0, 0, 0);
3518  layout->addWidget(bb);
3519 
3520  set_type(LIVES_WIDGET_TYPE_DIALOG);
3521 
3522  add_child(actionArea);
3523  add_child(contentArea);
3524 
3525  }
3526 
3527  LiVESWidget *get_content_area() {
3528  return contentArea;
3529  }
3530 
3531  LiVESWidget *get_action_area() {
3532  return actionArea;
3533  }
3534 
3535  LiVESWidget *get_layout() {
3536  if (layout == NULL) {
3537  layout = new LiVESVBox;
3538  (static_cast<QDialog *>(this))->setLayout(dynamic_cast<QLayout *>(layout));
3539  if ((static_cast<LiVESWidget *>(this))->isVisible()) layout->setVisible(true);
3540  add_child(layout);
3541  }
3542  return layout;
3543  }
3544 
3545 private:
3546  LiVESWidget *layout;
3547  LiVESWidget *contentArea;
3548  LiVESWidget *actionArea;
3549 };
3550 
3551 
3552 typedef void LiVESAboutDialog;
3553 
3554 
3555 class LiVESAlignment: public LiVESWidget, public QGridLayout {
3556 public:
3557  float xalign, yalign, xscale, yscale;
3558 
3559  LiVESAlignment(float xxalign, float yyalign, float xxscale, float yyscale) :
3560  xalign(xxalign),
3561  yalign(yyalign),
3562  xscale(xxscale),
3563  yscale(yyscale) {
3564  set_type(LIVES_WIDGET_TYPE_ALIGNMENT);
3565  }
3566 
3567  void set_alignment(float xxalign, float yyalign, float xxscale, float yyscale) {
3568  xalign = xxalign;
3569  yalign = yyalign;
3570  xscale = xxscale;
3571  yscale = yyscale;
3572 
3573  // do something with layout spacers
3574  // or setContentsmargins()
3575 
3576  }
3577 
3578 
3579 };
3580 
3581 
3582 class LiVESImage : public LiVESWidget, public QImage {
3583 public:
3584 
3585  LiVESImage() {
3586  init();
3587  }
3588 
3589  LiVESImage(QImage *lim) {
3590  init();
3591  };
3592 
3593  LiVESImage(int width, int height, QImage::Format fmt) {
3594  init();
3595  }
3596 
3597  LiVESImage(uint8_t *data, int width, int height, int bpl, QImage::Format fmt, QImageCleanupFunction cleanupFunction,
3598  livespointer cleanupInfo) {
3599  init();
3600  }
3601 
3602 private:
3603  void init() {
3604  set_type(LIVES_WIDGET_TYPE_IMAGE);
3605  }
3606 
3607 };
3608 
3609 
3610 
3611 
3612 class LiVESArrow : public LiVESImage {
3613 public:
3614  LiVESArrow(QImage *image) {
3615  set_type(LIVES_WIDGET_TYPE_ARROW);
3616  }
3617 };
3618 
3619 // rendertypes
3620 #define LIVES_CELL_RENDERER_TEXT 1
3621 #define LIVES_CELL_RENDERER_SPIN 2
3622 #define LIVES_CELL_RENDERER_TOGGLE 3
3623 #define LIVES_CELL_RENDERER_PIXBUF 4
3624 
3625 
3626 typedef struct {
3627  const char *attr;
3628  int col;
3629 } tvattrcol;
3630 
3631 typedef QHeaderView::ResizeMode LiVESTreeViewColumnSizing;
3632 
3633 #define LIVES_TREE_VIEW_COLUMN_GROW_ONLY QHeaderView::Stretch
3634 #define LIVES_TREE_VIEW_COLUMN_AUTOSIZE QHeaderView::ResizeToContents
3635 #define LIVES_TREE_VIEW_COLUMN_FIXED QHeaderView::Fixed
3636 
3637 typedef class LiVESTreeView LiVESTreeView;
3638 typedef LiVESTreeView LiVESTreeSelection;
3639 
3640 
3641 class LiVESTreeViewColumn : public LiVESObject, public QStyledItemDelegate {
3642  friend LiVESTreeView;
3643 
3644 public:
3645 
3646  LiVESTreeViewColumn(int rendertype) {
3647  fwidth = -1;
3648  }
3649 
3650  void set_title(const char *xtitle) {
3651  title = strdup(xtitle);
3652  }
3653 
3654  void set_expand(boolean xexpand) {
3655  expand = xexpand;
3656  }
3657 
3658  void add_attribute(const char *attr, int col) {
3659  tvattrcol *attrcol = new tvattrcol;
3660  attrcol->attr = strdup(attr);
3661  attrcol->col = col;
3662  attributes.push_back(attrcol);
3663  }
3664 
3665  void set_sizing(LiVESTreeViewColumnSizing xsizing) {
3666  sizing = xsizing;
3667  }
3668 
3669 
3670  void set_fixed_width(int xfwidth) {
3671  fwidth = xfwidth;
3672  }
3673 
3674 
3675  QList<tvattrcol *> get_attributes() {
3676  return attributes;
3677  }
3678 
3679 
3680  ~LiVESTreeViewColumn() {
3681  delete title;
3682  for (int i=0; i < attributes.size(); i++) {
3683  delete attributes[i]->attr;
3684  }
3685  }
3686 
3687 
3688 protected:
3689  int fwidth;
3690  int rendertype;
3691  LiVESTreeViewColumnSizing sizing;
3692  QList<tvattrcol *>attributes;
3693  const char *title;
3694  boolean expand;
3695 };
3696 
3697 
3698 typedef LiVESTreeViewColumn LiVESCellRenderer;
3699 
3700 
3701 typedef QAbstractItemView::SelectionMode LiVESSelectionMode;
3702 #define LIVES_SELECTION_NONE QAbstractItemView::NoSelection
3703 #define LIVES_SELECTION_SINGLE QAbstractItemView::SingleSelection
3704 #define LIVES_SELECTION_MULTIPLE QAbstractItemView::MultiSelection
3705 
3706 
3707 typedef class LiVESTreeStore LiVESTreeStore;
3708 
3709 
3710 class LiVESTreeModel : public LiVESObject, public QStandardItemModel {
3711  friend LiVESTreeStore;
3712 
3713 public:
3714 
3715  QStandardItemModel *to_qsimodel() {
3716  QStandardItemModel *qsim = static_cast<QStandardItemModel *>(this);
3717  QVariant qv = QVariant::fromValue(static_cast<LiVESObject *>(this));
3718  qsim->setProperty("LiVESObject", qv);
3719  return qsim;
3720  }
3721 
3722  int get_coltype(int index) {
3723  return coltypes[index];
3724  }
3725 
3726  void set_tree_widget(LiVESTreeView *twidget);
3727  QTreeWidget *get_qtree_widget();
3728 
3729 protected:
3730  void set_coltypes(int ncols, int *types) {
3731  for (int i = 0; i < ncols; i++) {
3732  coltypes.append(types[i]);
3733  }
3734  }
3735 
3736 
3737 private:
3738  LiVESTreeView *widget;
3739  QList<int> coltypes;
3740 
3741 };
3742 
3743 
3744 typedef LiVESTreeModel LiVESListModel;
3745 
3746 
3747 class LiVESTreeView : public LiVESWidget, public QTreeWidget {
3748  //Q_OBJECT
3749 
3750 public:
3751  LiVESTreeView() {
3752  set_type(LIVES_WIDGET_TYPE_TREE_VIEW);
3753 
3754  QAbstractSlider *sbar = static_cast<QAbstractSlider *>(horizontalScrollBar());
3755  hadj = new LiVESAdjustment(sbar->value(), sbar->minimum(), sbar->maximum(), sbar->singleStep(), sbar->pageStep(), -1.);
3756  hadj->set_owner(this);
3757  sbar->connect(sbar, SIGNAL(valueChanged(int)), static_cast<QObject *>(static_cast<LiVESObject *>(this)), SLOT(hvalue_changed(int)));
3758 
3759  sbar = static_cast<QAbstractSlider *>(verticalScrollBar());
3760  vadj = new LiVESAdjustment(sbar->value(), sbar->minimum(), sbar->maximum(), sbar->singleStep(), sbar->pageStep(), -1.);
3761  vadj->set_owner(this);
3762  sbar->connect(sbar, SIGNAL(valueChanged(int)), static_cast<QObject *>(static_cast<LiVESObject *>(this)), SLOT(vvalue_changed(int)));
3763 
3764  }
3765 
3766  void set_model(LiVESTreeModel *xmodel) {
3767  model = xmodel;
3768  xmodel->set_tree_widget(this);
3769  QStandardItemModel *qmodel = xmodel->to_qsimodel();
3770  (static_cast<QAbstractItemView *>(this))->setModel(static_cast<QAbstractItemModel *>(qmodel));
3771  }
3772 
3773  LiVESTreeModel *get_model() {
3774  return model;
3775  }
3776 
3777 
3778 
3779  void append_column(LiVESTreeViewColumn *col) {
3780  // make QList from data in column x
3781 
3782  // get stuff from attributes
3783  QList<tvattrcol *> ql = col->get_attributes();
3784  QList<QStandardItem *> qvals;
3785  QStandardItemModel *qmodel = model->to_qsimodel();
3786 
3787  int attrcol;
3788 
3789  for (int i=0; i < ql.size(); i++) {
3790  attrcol = ql[i]->col;
3791  if (!strcmp(ql[i]->attr,"text")) {
3792  // TODO
3793  // make QList of QString from model col
3794  qmodel->appendColumn(qvals);
3795  }
3796 
3797  else if (!strcmp(ql[i]->attr,"pixbuf")) {
3798  // make QList of QIcons from model col
3799  qmodel->appendColumn(qvals);
3800  }
3801 
3802  else if (!strcmp(ql[i]->attr,"active")) {
3803  // make QList of checkable from model col
3804  qmodel->appendColumn(qvals);
3805  }
3806  }
3807 
3808  int newcol = qmodel->columnCount();
3809  QTreeView *qtv = static_cast<QTreeView *>(this);
3810  if (col->fwidth != -1) {
3811  qtv->setColumnWidth(newcol, col->fwidth);
3812  }
3813 
3814  QHeaderView *qv = (static_cast<QTreeView *>(this))->header();
3815  qv->setSectionResizeMode(newcol, col->sizing);
3816 
3817  //resizeColumnToContents()
3818 
3819  }
3820 
3821  LiVESAdjustment *get_hadj() {
3822  return hadj;
3823  }
3824 
3825  LiVESAdjustment *get_vadj() {
3826  return vadj;
3827  }
3828 
3829 
3830  /* public slots:
3831 
3832  void hvalue_changed(int newval) {
3833  hadj->freeze();
3834  hadj->set_value(newval);
3835  hadj->thaw();
3836  }
3837 
3838  void vvalue_changed(int newval) {
3839  vadj->freeze();
3840  vadj->set_value(newval);
3841  vadj->thaw();
3842  }
3843  */
3844 
3845 private:
3846  LiVESTreeModel *model;
3847  LiVESAdjustment *hadj, *vadj;
3848 };
3849 
3850 
3851 #define LIVES_COL_TYPE_STRING 1
3852 #define LIVES_COL_TYPE_INT 2
3853 #define LIVES_COL_TYPE_UINT 3
3854 #define LIVES_COL_TYPE_BOOLEAN 4
3855 #define LIVES_COL_TYPE_PIXBUF 5
3856 
3857 
3858 typedef QTreeWidgetItem LiVESTreeIter;
3859 
3860 void LiVESTreeModel::set_tree_widget(LiVESTreeView *twidget) {
3861  widget = twidget;
3862 }
3863 
3864 QTreeWidget *LiVESTreeModel::get_qtree_widget() {
3865  return static_cast<QTreeWidget *>(widget);
3866 }
3867 
3868 
3869 
3870 class LiVESTreeStore : public LiVESTreeModel {
3871 public:
3872  LiVESTreeStore(int ncols, int *types) {}
3873 
3874 };
3875 
3876 
3877 class LiVESListStore : public LiVESListModel {
3878 public:
3879  LiVESListStore(int ncols, int *types) {}
3880 
3881 };
3882 
3883 
3884 
3885 
3886 
3887 void LiVESAdjustment::set_value(double newval) {
3888  if (newval != value) {
3889  value = newval;
3890 
3891  if (frozen) return;
3892 
3893  if (LIVES_IS_SCALE(owner)) {
3894  (dynamic_cast<QAbstractSlider *>(owner))->setValue(newval);
3895  } else if (LIVES_IS_SCROLLBAR(owner)) {
3896  (dynamic_cast<QScrollBar *>(owner))->setValue(newval);
3897  } else if (LIVES_IS_SPIN_BUTTON(owner)) {
3898  //
3899  (dynamic_cast<QDoubleSpinBox *>(owner))->setValue(newval);
3900  } else if (LIVES_IS_TREE_VIEW(owner)) {
3901  if (this == (dynamic_cast<LiVESTreeView *>(owner))->get_hadj()) {
3902  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setValue(newval);
3903  } else {
3904  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setValue(newval);
3905  }
3906  } else if (LIVES_IS_SCROLLED_WINDOW(owner)) {
3907  if (this == (dynamic_cast<LiVESScrolledWindow *>(owner))->get_hadj()) {
3908  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setValue(newval);
3909  } else {
3910  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setValue(newval);
3911  }
3912  }
3913  }
3914 }
3915 
3916 
3917 void LiVESAdjustment::set_upper(double newval) {
3918  if (newval != upper) {
3919  upper = newval;
3920 
3921  if (frozen) return;
3922 
3923  if (LIVES_IS_SCALE(owner)) {
3924  (dynamic_cast<QAbstractSlider *>(owner))->setMaximum(newval);
3925  } else if (LIVES_IS_SCROLLBAR(owner)) {
3926  //
3927  (dynamic_cast<QScrollBar *>(owner))->setMaximum(newval);
3928  } else if (LIVES_IS_SPIN_BUTTON(owner)) {
3929  //
3930  (dynamic_cast<QDoubleSpinBox *>(owner))->setMaximum(newval);
3931  } else if (LIVES_IS_TREE_VIEW(owner)) {
3932  if (this == (dynamic_cast<LiVESTreeView *>(owner))->get_hadj()) {
3933  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setMaximum(newval);
3934  } else {
3935  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setMaximum(newval);
3936  }
3937  } else if (LIVES_IS_SCROLLED_WINDOW(owner)) {
3938  if (this == (dynamic_cast<LiVESScrolledWindow *>(owner))->get_hadj()) {
3939  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setMaximum(newval);
3940  } else {
3941  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setMaximum(newval);
3942  }
3943  }
3944  }
3945 
3946 
3947 }
3948 
3949 
3950 
3951 void LiVESAdjustment::set_lower(double newval) {
3952  if (newval != lower) {
3953  lower = newval;
3954  if (frozen) return;
3955 
3956  if (LIVES_IS_SCALE(owner)) {
3957  (dynamic_cast<QAbstractSlider *>(owner))->setMinimum(newval);
3958  } else if (LIVES_IS_SCROLLBAR(owner)) {
3959  //
3960  (dynamic_cast<QScrollBar *>(owner))->setMinimum(newval);
3961  } else if (LIVES_IS_SPIN_BUTTON(owner)) {
3962  //
3963  (dynamic_cast<QDoubleSpinBox *>(owner))->setMinimum(newval);
3964  } else if (LIVES_IS_TREE_VIEW(owner)) {
3965  if (this == (dynamic_cast<LiVESTreeView *>(owner))->get_hadj()) {
3966  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setMinimum(newval);
3967  } else {
3968  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setMinimum(newval);
3969  }
3970  } else if (LIVES_IS_SCROLLED_WINDOW(owner)) {
3971  if (this == (dynamic_cast<LiVESScrolledWindow *>(owner))->get_hadj()) {
3972  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setMinimum(newval);
3973  } else {
3974  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setMinimum(newval);
3975  }
3976  }
3977  }
3978 }
3979 
3980 
3981 
3982 void LiVESAdjustment::set_step_increment(double newval) {
3983  if (newval != step_increment) {
3984  step_increment = newval;
3985 
3986  if (frozen) return;
3987 
3988  if (LIVES_IS_SCALE(owner)) {
3989  (dynamic_cast<QAbstractSlider *>(owner))->setSingleStep(newval);
3990  } else if (LIVES_IS_SCROLLBAR(owner)) {
3991  //
3992  (dynamic_cast<QScrollBar *>(owner))->setSingleStep(newval);
3993  } else if (LIVES_IS_SPIN_BUTTON(owner)) {
3994  //
3995  (dynamic_cast<QDoubleSpinBox *>(owner))->setSingleStep(newval);
3996  } else if (LIVES_IS_TREE_VIEW(owner)) {
3997  if (this == (dynamic_cast<LiVESTreeView *>(owner))->get_hadj()) {
3998  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setSingleStep(newval);
3999  } else {
4000  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setSingleStep(newval);
4001  }
4002  } else if (LIVES_IS_SCROLLED_WINDOW(owner)) {
4003  if (this == (dynamic_cast<LiVESScrolledWindow *>(owner))->get_hadj()) {
4004  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setSingleStep(newval);
4005  } else {
4006  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setSingleStep(newval);
4007  }
4008  }
4009  }
4010 }
4011 
4012 
4013 void LiVESAdjustment::set_page_increment(double newval) {
4014  if (newval != page_increment) {
4015  page_increment = newval;
4016 
4017  if (frozen) return;
4018 
4019  if (LIVES_IS_SCALE(owner)) {
4020  (dynamic_cast<QAbstractSlider *>(owner))->setPageStep(newval);
4021  } else if (LIVES_IS_SCROLLBAR(owner)) {
4022  //
4023  (dynamic_cast<QScrollBar *>(owner))->setPageStep(newval);
4024  } else if (LIVES_IS_TREE_VIEW(owner)) {
4025  if (this == (dynamic_cast<LiVESTreeView *>(owner))->get_hadj()) {
4026  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setPageStep(newval);
4027  } else {
4028  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setPageStep(newval);
4029  }
4030  } else if (LIVES_IS_SCROLLED_WINDOW(owner)) {
4031  if (this == (dynamic_cast<LiVESScrolledWindow *>(owner))->get_hadj()) {
4032  (dynamic_cast<QAbstractScrollArea *>(owner))->horizontalScrollBar()->setPageStep(newval);
4033  } else {
4034  (dynamic_cast<QAbstractScrollArea *>(owner))->verticalScrollBar()->setPageStep(newval);
4035  }
4036  }
4037  }
4038 }
4039 
4040 
4041 void LiVESAdjustment::set_page_size(double newval) {
4042  // TODO
4043  if (newval != page_size) {
4044  page_size = newval;
4045 
4046  if (frozen) return;
4047  }
4048 }
4049 
4050 
4051 
4052 class LiVESTable : public LiVESWidget, public QGridLayout {
4053 
4054 public:
4055  LiVESTable() {
4056  set_type(LIVES_WIDGET_TYPE_TABLE);
4057  }
4058 
4059 
4060 private:
4061  LiVESWidget *layout;
4062 
4063 };
4064 
4065 
4066 typedef QWindow LiVESXWindow;
4067 
4068 typedef class LiVESImage LiVESPixbuf;
4069 
4070 typedef LiVESWidget LiVESEditable;
4071 typedef LiVESWidget LiVESContainer;
4072 typedef LiVESWidget LiVESMenuShell;
4073 typedef LiVESWidget LiVESBin;
4074 
4075 typedef QSlider LiVESScaleButton; // TODO - create
4076 typedef void LiVESExpander; // TODO - create
4077 
4078 
4079 void qt_jpeg_save(LiVESPixbuf *pixbuf, const char *fname, LiVESError **errptr, int quality) {
4080 #ifdef IS_MINGW
4081  QImageWriter qiw(QString::fromUtf8(fname),"jpeg");
4082 #else
4083  QImageWriter qiw(QString::fromLocal8Bit(fname),"jpeg");
4084 #endif
4085  qiw.setQuality(quality);
4086  if (!qiw.write(static_cast<QImage>(*pixbuf))) {
4087  if (errptr != NULL) {
4088  *errptr = (LiVESError *)malloc(sizeof(LiVESError));
4089  (*errptr)->code = qiw.error();
4090  (*errptr)->message = strdup(qiw.errorString().toUtf8().constData());
4091  }
4092  }
4093 }
4094 
4095 
4096 void qt_png_save(LiVESPixbuf *pixbuf, const char *fname, LiVESError **errptr, int cmp) {
4097 #ifdef IS_MINGW
4098  QImageWriter qiw(QString::fromUtf8(fname),"png");
4099 #else
4100  QImageWriter qiw(QString::fromLocal8Bit(fname),"png");
4101 #endif
4102  qiw.setCompression(cmp);
4103  if (!qiw.write(static_cast<QImage>(*pixbuf))) {
4104  if (errptr != NULL) {
4105  *errptr = (LiVESError *)malloc(sizeof(LiVESError));
4106  (*errptr)->code = qiw.error();
4107  (*errptr)->message = strdup(qiw.errorString().toUtf8().constData());
4108  }
4109  }
4110 }
4111 
4112 
4113 
4114 // scrolledwindow policies
4115 typedef Qt::ScrollBarPolicy LiVESPolicyType;
4116 #define LIVES_POLICY_AUTOMATIC Qt::ScrollBarAsNeeded
4117 #define LIVES_POLICY_NEVER Qt::ScrollBarAlwaysOff
4118 #define LIVES_POLICY_ALWAYS Qt::ScrollBarAlwaysOn
4119 
4120 
4121 class LiVESFrame : public LiVESWidget, public QGroupBox {
4122 public:
4123  LiVESFrame(QString text) {
4124  set_type(LIVES_WIDGET_TYPE_FRAME);
4125 
4126  LiVESWidget *label_widget = new LiVESLabel(text);
4127  set_label_widget(label_widget);
4128  }
4129 
4130 
4131  void set_label(QString text) {
4132  label_widget->set_text(text);
4133  }
4134 
4135 
4136  void set_label_widget(LiVESWidget *widget) {
4137  if (label_widget != NULL) {
4138  remove_child(static_cast<LiVESWidget *>(label_widget));
4139  }
4140  if (widget != NULL) {
4141  add_child(label_widget);
4142  label_widget = dynamic_cast<LiVESLabel *>(widget);
4143  label_widget->set_owner(this);
4144  setTitle(label_widget->text());
4145  } else {
4146  label_widget = NULL;
4147  setTitle(NULL);
4148  }
4149 
4150  }
4151 
4152  LiVESWidget *get_label_widget() {
4153  return static_cast<LiVESWidget *>(label_widget);
4154  }
4155 
4156 
4157 
4158  LiVESWidget *get_layout() {
4159  if (layout == NULL) {
4160  layout = new LiVESVBox;
4161  (static_cast<QGroupBox *>(this))->setLayout(dynamic_cast<QLayout *>(layout));
4162  if ((static_cast<LiVESWidget *>(this))->isVisible()) layout->setVisible(true);
4163  add_child(layout);
4164  }
4165  return layout;
4166  }
4167 
4168 
4169 private:
4170  LiVESWidget *layout;
4171  LiVESLabel *label_widget;
4172 
4173 
4174 };
4175 
4176 
4177 class LiVESFileChooser : public LiVESWidget, public QFileDialog {
4178 public:
4179  LiVESFileChooser() {
4180  set_type(LIVES_WIDGET_TYPE_FILE_CHOOSER);
4181  }
4182 
4183 };
4184 
4185 
4186 typedef int LiVESFileChooserAction;
4187 #define LIVES_FILE_CHOOSER_ACTION_OPEN 1
4188 #define LIVES_FILE_CHOOSER_ACTION_SAVE 2
4189 #define LIVES_FILE_CHOOSER_ACTION_SELECT_FOLDER 3
4190 #define LIVES_FILE_CHOOSER_ACTION_CREATE_FOLDER 4
4191 #define LIVES_FILE_CHOOSER_ACTION_SELECT_DEVICE 5
4192 
4193 
4194 class LiVESNotebook : public LiVESWidget, public QTabWidget {
4195 public:
4196 
4197  LiVESNotebook() {
4198  set_type(LIVES_WIDGET_TYPE_NOTEBOOK);
4199  }
4200 
4201  ~LiVESNotebook() {
4202  for (int i = 0; i < label_widgets.size(); i++) {
4203  label_widgets[i]->dec_refcount();
4204  }
4205  }
4206 
4207  void set_tab_label(LiVESWidget *child, LiVESWidget *xlabel) {
4208  int i = get_child_index(child);
4209  if (i == -1) return;
4210 
4211  if (xlabel != NULL) {
4212  label_widgets[i]->dec_refcount();
4213  LiVESLabel *label = dynamic_cast<LiVESLabel *>(xlabel);
4214  label_widgets[i] = label;
4215  label->set_owner(this);
4216  QLabel *qlabel =static_cast<QLabel *>(label);
4217  setTabText(i, qlabel->text());
4218  }
4219  }
4220 
4221 
4222  void append_page() {
4223  LiVESWidget *label_widget = new LiVESLabel(NULL);
4224  label_widgets.append(label_widget);
4225  }
4226 
4227 private:
4228  QList <LiVESWidget *> label_widgets;
4229 
4230 
4231 };
4232 
4233 
4234 
4235 class LiVESToolbar : public LiVESWidget, public QToolBar {
4236 public:
4237 
4238  LiVESToolbar() {
4239  set_type(LIVES_WIDGET_TYPE_TOOLBAR);
4240  }
4241 
4242  void add_action(QAction *act, int pos) {
4243  actions.insert(pos, act);
4244  }
4245 
4246  QAction *get_action(int pos) {
4247  return actions.at(pos);
4248  }
4249 
4250  int num_actions() {
4251  return actions.size();
4252  }
4253 
4254 private:
4255  QList<QAction *>actions;
4256 
4257 
4258 };
4259 
4260 
4261 
4262 class LiVESColorButton : public LiVESButtonBase, public QPushButton {
4263  //Q_OBJECT
4264 
4265 public:
4266 
4267  LiVESColorButton(const LiVESWidgetColor *col) {
4268  set_type(LIVES_WIDGET_TYPE_COLOR_BUTTON);
4269  static_cast<QObject *>(static_cast<QPushButton *>(this))->connect(static_cast<QObject *>(static_cast<QPushButton *>(this)),
4270  SIGNAL(clicked()),
4271  static_cast<QObject *>(static_cast<QPushButton *>(this)),
4272  SLOT(onClicked()));
4273 
4274  use_alpha = FALSE;
4275  set_colour(col);
4276  }
4277 
4278  void set_colour(const LiVESWidgetColor *col) {
4279  QColor xcolor(col->red * 255., col->green * 255., col->blue * 255., col->alpha * 255.);
4280  set_colour(xcolor);
4281  }
4282 
4283  void set_colour(QColor xcolour) {
4284  if (colour != xcolour) {
4285  colour = xcolour;
4286  QPushButton *qpb = static_cast<QPushButton *>(this);
4287  QPalette p = qpb->palette();
4288  QColor mycolour = xcolour;
4289  if (!use_alpha) mycolour.setAlpha(255);
4290  p.setColor(QPalette::Button, mycolour);
4291  qpb->setPalette(p);
4292 
4293  //Q_EMIT changed();
4294  }
4295  }
4296 
4297 
4298  QColor get_colour() {
4299  return colour;
4300  }
4301 
4302  void get_colour(LiVESWidgetColor *col) {
4303  col->red = (float)colour.red() / 255.;
4304  col->green = (float)colour.green() / 255.;
4305  col->blue = (float)colour.blue() / 255.;
4306  col->alpha = (float)colour.alpha() / 255.;
4307  }
4308 
4309 
4310  void set_title(const char *xtitle) {
4311  title = QString::fromUtf8(xtitle);
4312  }
4313 
4314  void set_use_alpha(boolean val) {
4315  use_alpha = val;
4316  }
4317 
4318 
4319  /* Q_SIGNALS:
4320  void changed();
4321 
4322  private Q_SLOTS:
4323 
4324  void onClicked() {
4325  QColor mycolour = colour;
4326  if (!use_alpha) mycolour.setAlpha(255);
4327  QColorDialog dlg(mycolour);
4328  dlg.setWindowTitle(title);
4329  dlg.setOption(QColorDialog::ShowAlphaChannel, use_alpha);
4330  if(dlg.exec() == QDialog::Accepted) {
4331  set_colour(dlg.selectedColor());
4332  }
4333  if (!use_alpha) colour.setAlpha(255);
4334  }*/
4335 
4336 private:
4337  QColor colour;
4338  boolean use_alpha;
4339  QString title;
4340 };
4341 
4342 
4343 
4344 class LiVESTimer : public LiVESObject, public QTimer {
4345 public:
4346 
4347  LiVESTimer(uint32_t interval, LiVESWidgetSourceFunc xfunc, livespointer data);
4348 
4349  uint32_t get_handle() {
4350  return handle;
4351  }
4352 
4353  /* public slots:*/
4354 
4355  void update();
4356 
4357 
4358 private:
4359  uint32_t handle;
4360  LiVESWidgetSourceFunc func;
4361  livespointer data;
4362 
4363 };
4364 
4365 static QList<LiVESTimer *> static_timers;
4366 
4367 
4368 LiVESTimer::LiVESTimer(uint32_t interval, LiVESWidgetSourceFunc xfunc, livespointer data) {
4369  set_type(LIVES_OBJECT_TYPE_TIMER);
4370  static_timers.append(this);
4371 
4372  static_cast<QObject *>(static_cast<QTimer *>(this))->connect(static_cast<QObject *>(static_cast<QTimer *>(this)),
4373  SIGNAL(timeout()),
4374  static_cast<QObject *>(static_cast<QTimer *>(this)),
4375  SLOT(update()));
4376  start(interval);
4377 
4378 }
4379 
4380 
4381 void LiVESTimer::update() {
4382  // ret false to stop
4383  boolean ret = (func)(data);
4384  if (!ret) {
4385  stop();
4386  static_timers.removeOne(this);
4387  }
4388 }
4389 
4390 
4391 void remove_static_timer(uint32_t handle) {
4392  for (int i = 0; i < static_timers.size(); i++) {
4393  if (static_timers.at(i)->get_handle() == handle) {
4394  static_timers.removeOne(static_timers.at(i));
4395  break;
4396  }
4397  }
4398 }
4399 
4400 
4401 typedef Qt::ToolButtonStyle LiVESToolbarStyle;
4402 #define LIVES_TOOLBAR_ICONS Qt::ToolButtonIconOnly
4403 #define LIVES_TOOLBAR_TEXT Qt::ToolButtonTextOnly
4404 
4405 typedef QSize LiVESRequisition;
4406 
4407 typedef int LiVESTextIter;
4408 
4409 class LiVESTreePath {
4410 public:
4411 
4412  LiVESTreePath(const char *string) {
4413  QString qs(string);
4414  QStringList qsl = qs.split(":");
4415  QList<int> qli;
4416 
4417  for (int i=0; i < qsl.size(); i++) {
4418  qli.append(qsl.at(i).toInt());
4419  }
4420 
4421  init(qli);
4422  }
4423 
4424  LiVESTreePath(QList<int> qli) {
4425  init(qli);
4426  }
4427 
4428  ~LiVESTreePath() {
4429  delete indices;
4430  }
4431 
4432 
4433  int get_depth() {
4434  return cnt;
4435  }
4436 
4437 
4438  int *get_indices() {
4439  return indices;
4440  }
4441 
4442 private:
4443  int *indices;
4444  int cnt;
4445 
4446  void init(QList<int> qli) {
4447  cnt = qli.size();
4448  indices = (int *)(malloc(cnt * sizeof(int)));
4449  for (int i=0; i < cnt; i++) {
4450  indices[i] = qli.at(i);
4451  }
4452  }
4453 
4454 };
4455 
4456 
4457 typedef Qt::Orientation LiVESOrientation;
4458 #define LIVES_ORIENTATION_HORIZONTAL Qt::Horizontal
4459 #define LIVES_ORIENTATION_VERTICAL Qt::Vertical
4460 
4461 typedef int LiVESButtonBoxStyle;
4462 #define LIVES_BUTTONBOX_DEFAULT_STYLE 0
4463 #define LIVES_BUTTONBOX_SPREAD 1
4464 #define LIVES_BUTTONBOX_EDGE 2
4465 #define LIVES_BUTTONBOX_START 3
4466 #define LIVES_BUTTONBOX_END 4
4467 #define LIVES_BUTTONBOX_CENTER 5
4468 
4469 typedef int LiVESReliefStyle;
4470 
4471 #define LIVES_RELIEF_NORMAL 2
4472 #define LIVES_RELIEF_HALF 1
4473 #define LIVES_RELIEF_NONE 0
4474 
4475 #define LIVES_ACCEL_VISIBLE 1
4476 
4477 typedef int LiVESWindowType;
4478 #define LIVES_WINDOW_TOPLEVEL Qt::Window
4479 #define LIVES_WINDOW_POPUP Qt::Popup
4480 
4481 typedef QFrame::Shadow LiVESShadowType;
4482 #define LIVES_SHADOW_NONE QFrame::Plain
4483 #define LIVES_SHADOW_IN QFrame::Raised
4484 #define LIVES_SHADOW_OUT QFrame::Sunken
4485 #define LIVES_SHADOW_ETCHED_IN QFrame::Raised
4486 #define LIVES_SHADOW_ETCHED_OUT QFrame::Sunken
4487 
4488 
4489 
4490 typedef int LiVESPositionType;
4491 #define LIVES_POS_LEFT 1
4492 #define LIVES_POS_RIGHT 2
4493 #define LIVES_POS_TOP 3
4494 #define LIVES_POS_BOTTOM 4
4495 
4496 
4497 #define LIVES_WIDGET(a) ((LiVESWidget *)a)
4498 
4499 
4500 #define LIVES_EDITABLE(a) (a)
4501 
4502 #define LIVES_CONTAINER(a) LIVES_WIDGET(a)
4503 #define LIVES_GUI_OBJECT(a) LIVES_WIDGET(a)
4504 #define LIVES_EXPANDER(a) LIVES_WIDGET(a)
4505 #define LIVES_BIN(a) LIVES_WIDGET(a)
4506 #define LIVES_MENU_SHELL(a) LIVES_WIDGET(a)
4507 
4508 #define LIVES_WIDGET_OBJECT(a) ((LiVESObject *)a)
4509 #define LIVES_COMBO(a) ((LiVESCombo *)a)
4510 #define LIVES_HBOX(a) ((LiVESHBox *)a)
4511 #define LIVES_VBOX(a) ((LiVESVBox *)a)
4512 #define LIVES_BOX(a) ((LiVESBox *)a)
4513 #define LIVES_ALIGNMENT(a) ((LiVESAlignment *)a)
4514 #define LIVES_TOOLBAR(a) ((LiVESToolbar *)a)
4515 #define LIVES_TOOL_BUTTON(a) ((LiVESToolButton *)a)
4516 #define LIVES_EVENT_BOX(a) ((LiVESEventBox *)a)
4517 #define LIVES_DRAWING_AREA(a) ((LiVESDrawingArea *)a)
4518 #define LIVES_TEXT_VIEW(a) ((LiVESTextView *)a)
4519 #define LIVES_TEXT_BUFFER(a) ((LiVESTextBuffer *)a)
4520 #define LIVES_BUTTON_BOX(a) ((LiVESButtonBox *)a)
4521 #define LIVES_FRAME(a) ((LiVESFrame *)a)
4522 #define LIVES_SCALE(a) ((LiVESScale *)a)
4523 #define LIVES_RANGE(a) ((LiVESRange *)a)
4524 #define LIVES_ADJUSTMENT(a) ((LiVESAdjustment *)a)
4525 #define LIVES_TABLE(a) ((LiVESTable *)a)
4526 #define LIVES_NOTEBOOK(a) ((LiVESNotebook *)a)
4527 #define LIVES_MENU(a) ((LiVESMenu *)a)
4528 #define LIVES_MENU_ITEM(a) ((LiVESMenuItem *)a)
4529 #define LIVES_MENU_TOOL_ITEM(a) ((LiVESMenuToolItem *)a)
4530 #define LIVES_MENU_TOOL_BUTTON(a) ((LiVESMenuToolButton *)a)
4531 #define LIVES_RULER(a) ((LiVESRuler *)a)
4532 #define LIVES_CHECK_MENU_ITEM(a) ((LiVESCheckMenuItem *)a)
4533 #define LIVES_IMAGE(a) ((LiVESImage *)a)
4534 #define LIVES_PROGRESS_BAR(a) ((LiVESProgressBar *)a)
4535 #define LIVES_BUTTON(a) ((LiVESButton *)a)
4536 #define LIVES_SPIN_BUTTON(a) ((LiVESSpinButton *)a)
4537 #define LIVES_SCALE_BUTTON(a) ((LiVESScaleButton *)a)
4538 #define LIVES_TOGGLE_BUTTON(a) ((LiVESToggleButton *)a)
4539 #define LIVES_RADIO_BUTTON(a) ((LiVESRadioButton *)a)
4540 #define LIVES_RADIO_MENU_ITEM(a) ((LiVESRadioMenuItem *)a)
4541 #define LIVES_COLOR_BUTTON(a) ((LiVESColorButton *)a)
4542 #define LIVES_DIALOG(a) ((LiVESDialog *)a)
4543 #define LIVES_LABEL(a) ((LiVESLabel *)a)
4544 #define LIVES_ENTRY(a) ((LiVESEntry *)a)
4545 #define LIVES_PANED(a) ((LiVESPaned *)a)
4546 #define LIVES_FILE_CHOOSER(a) ((LiVESFileChooser *)a)
4547 #define LIVES_ACCEL_GROUP(a) ((LiVESAccelGroup *)a)
4548 #define LIVES_WINDOW(a) ((LiVESWindow *)a)
4549 #define LIVES_SCROLLED_WINDOW(a) ((LiVESScrolledWindow *)a)
4550 #define LIVES_TREE_MODEL(a) ((LiVESTreeModel *)a)
4551 #define LIVES_TREE_VIEW(a) ((LiVESTreeView *)a)
4552 #define LIVES_LIST_STORE(a) ((LiVESListStore *)a)
4553 #define LIVES_TOOL_ITEM(a) ((LiVESToolItem *)a)
4554 
4555 
4556 #define LIVES_STOCK_UNDO "edit-undo"
4557 #define LIVES_STOCK_REDO "edit-redo"
4558 #define LIVES_STOCK_ADD "list-add"
4559 #define LIVES_STOCK_REMOVE "list-remove"
4560 #define LIVES_STOCK_NO "media-record"
4561 #define LIVES_STOCK_QUIT "application-exit"
4562 #define LIVES_STOCK_OPEN "document-open"
4563 #define LIVES_STOCK_CLOSE "window-close"
4564 #define LIVES_STOCK_CLEAR "edit-clear"
4565 #define LIVES_STOCK_DELETE "edit-delete"
4566 #define LIVES_STOCK_SAVE_AS "document-save-as"
4567 #define LIVES_STOCK_SAVE "document-save"
4568 #define LIVES_STOCK_REFRESH "view-refresh"
4569 #define LIVES_STOCK_REVERT_TO_SAVED "document-revert"
4570 #define LIVES_STOCK_GO_BACK "go-previous"
4571 #define LIVES_STOCK_GO_FORWARD "go-next"
4572 #define LIVES_STOCK_REFRESH "view-refresh"
4573 #define LIVES_STOCK_MEDIA_PLAY "media-playback-start"
4574 #define LIVES_STOCK_MEDIA_STOP "media-playback-stop"
4575 #define LIVES_STOCK_MEDIA_REWIND "media-seek-backward"
4576 #define LIVES_STOCK_MEDIA_RECORD "media-record"
4577 #define LIVES_STOCK_MEDIA_PAUSE "media-pause"
4578 #define LIVES_STOCK_PREFERENCES "preferences-system"
4579 #define LIVES_STOCK_DIALOG_INFO "dialog-information"
4580 #define LIVES_STOCK_MISSING_IMAGE "image-missing"
4581 
4582 
4583 #define LIVES_STOCK_YES "gtk-yes" // non-standard image ?
4584 #define LIVES_STOCK_APPLY "gtk-apply" // non-standard image ?
4585 #define LIVES_STOCK_CANCEL "gtk-cancel" // non-standard image ?
4586 #define LIVES_STOCK_OK "gtk-ok" // non-standard image ?
4587 
4588 
4589 char LIVES_STOCK_LABEL_CANCEL[32];
4590 char LIVES_STOCK_LABEL_OK[32];
4591 char LIVES_STOCK_LABEL_YES[32];
4592 char LIVES_STOCK_LABEL_NO[32];
4593 char LIVES_STOCK_LABEL_SAVE[32];
4594 char LIVES_STOCK_LABEL_SAVE_AS[32];
4595 char LIVES_STOCK_LABEL_OPEN[32];
4596 char LIVES_STOCK_LABEL_QUIT[32];
4597 char LIVES_STOCK_LABEL_APPLY[32];
4598 char LIVES_STOCK_LABEL_CLOSE[32];
4599 char LIVES_STOCK_LABEL_REVERT[32];
4600 char LIVES_STOCK_LABEL_REFRESH[32];
4601 char LIVES_STOCK_LABEL_DELETE[32];
4602 char LIVES_STOCK_LABEL_GO_FORWARD[32];
4603 
4604 
4605 typedef int LiVESAttachOptions;
4606 #define LIVES_EXPAND 1
4607 #define LIVES_SHRINK 2
4608 #define LIVES_FILL 3
4609 
4610 
4611 //typedef int LiVESWrapMode;
4612 //#define LIVES_WRAP_NONE QTextEdit::NoWrap
4613 //#define LIVES_WRAP_WORD QTextEdit::WidgetWidth
4614 
4615 typedef bool LiVESWrapMode;
4616 #define LIVES_WRAP_NONE false
4617 #define LIVES_WRAP_WORD true
4618 
4619 typedef Qt::Alignment LiVESJustification;
4620 
4621 #define LIVES_JUSTIFY_LEFT Qt::AlignLeft
4622 #define LIVES_JUSTIFY_RIGHT Qt::AlignRight
4623 #define LIVES_JUSTIFY_CENTER Qt::AlignHCenter
4624 #define LIVES_JUSTIFY_FILL Qt::AlignJustify
4625 
4626 extern "C" {
4627  boolean lives_container_remove(LiVESContainer *, LiVESWidget *);
4628 }
4629 
4630 
4631 LiVESWidget::~LiVESWidget() {
4632  if (LIVES_IS_SPIN_BUTTON(this)) {
4633  LiVESAdjustment *adj = (static_cast<LiVESSpinButton *>(this))->get_adj();
4634  adj->dec_refcount();
4635  }
4636 
4637  if (LIVES_IS_RANGE(this)) {
4638  LiVESAdjustment *adj = (dynamic_cast<LiVESRange *>(this))->get_adj();
4639  adj->dec_refcount();
4640  }
4641 
4642  if (LIVES_IS_TREE_VIEW(this)) {
4643  LiVESAdjustment *adj = (static_cast<LiVESTreeView *>(this))->get_hadj();
4644  adj->dec_refcount();
4645  adj = (static_cast<LiVESTreeView *>(this))->get_vadj();
4646  adj->dec_refcount();
4647  }
4648 
4649  if (LIVES_IS_SCROLLED_WINDOW(this)) {
4650  LiVESAdjustment *adj = (static_cast<LiVESScrolledWindow *>(this))->get_hadj();
4651  adj->dec_refcount();
4652  adj = (static_cast<LiVESScrolledWindow *>(this))->get_vadj();
4653  adj->dec_refcount();
4654  }
4655 
4656  // remove from parents children
4657  if (parent != NULL) {
4658  inc_refcount();
4659  parent->remove_child(this);
4660  }
4661 
4662  LiVESList *xchildren = children;
4663 
4664  // decref all children
4665  while (xchildren != NULL) {
4666  lives_container_remove(this, (LiVESWidget *)xchildren->data);
4667  xchildren = xchildren->next;
4668  }
4669 
4670  lives_list_free(children);
4671 }
4672 
4673 #define LINGO_ALIGN_LEFT Qt::AlignLeft
4674 #define LINGO_ALIGN_RIGHT Qt::AlignRight
4675 #define LINGO_ALIGN_CENTER Qt::AlignHCenter
4676 
4677 #define LINGO_SCALE 1
4678 
4679 typedef class lives_painter_t lives_painter_t;
4680 
4681 class LingoLayout : public LiVESObject {
4682 public:
4683  LingoLayout(const char *xtext, const char *xfont, double fsize) {
4684  text = QString::fromUtf8(xtext);
4685  font = QFont(QString::fromUtf8(xfont));
4686  font.setPointSizeF((float)fsize);
4687  align = LINGO_ALIGN_LEFT;
4688  }
4689 
4690  void set_alignment(int xalign) {
4691  align = xalign;
4692  }
4693 
4694  void set_text(const char *xtext, ssize_t len) {
4695  text = QString::fromUtf8(xtext, len);
4696  }
4697 
4698  void get_size(int *bwidth, int *bheight, int pwidth, int pheight);
4699 
4700  void set_coords(int xx, int xy, int xwidth, int xheight) {
4701  x = xx;
4702  y = xy;
4703  width = xwidth;
4704  height = xheight;
4705  }
4706 
4707  void render_text(lives_painter_t *painter);
4708 
4709 
4710 private:
4711  QString text;
4712  QFont font;
4713  int align;
4714  int x,y,width,height;
4715 };
4716 
4717 LIVES_INLINE void lingo_layout_set_alignment(LingoLayout *l, int alignment) {
4718  l->set_alignment(alignment);
4719 }
4720 
4721 
4722 LIVES_INLINE void lingo_layout_set_text(LingoLayout *l, const char *text, ssize_t len) {
4723  l->set_text(text, len);
4724 }
4725 
4726 
4727 LIVES_INLINE void lingo_layout_set_coords(LingoLayout *l, int x, int y, int width, int height) {
4728  l->set_coords(x, y, width, height);
4729 }
4730 
4731 
4732 LIVES_INLINE void lingo_layout_get_size(LingoLayout *l, int *rw, int *rh, int width, int height) {
4733  l->get_size(rw, rh, width, height);
4734 }
4735 
4736 
4737 LIVES_INLINE void lingo_painter_show_layout(lives_painter_t *painter, LingoLayout *l) {
4738  l->render_text(painter);
4739 }
4740 
4741 #endif
4742 
4743 
4744 
4745 #ifdef PAINTER_QPAINTER
4746 # include <QtGui/QPainter>
4747 
4748 //extern void lives_free(livespointer ptr);
4749 
4750 static void imclean(livespointer data) {
4751  lives_free(data);
4752 }
4753 
4754 typedef QImage::Format lives_painter_format_t;
4755 #define LIVES_PAINTER_FORMAT_A1 QImage::Format_Mono
4756 #define LIVES_PAINTER_FORMAT_A8 QImage::Format_Indexed8
4757 #define LIVES_PAINTER_FORMAT_ARGB32 QImage::Format_ARGB32_Premultiplied
4758 
4759 
4760 class lives_painter_surface_t : public QImage, public LiVESObject {
4761 public:
4762  int refcount;
4763 
4764  lives_painter_surface_t(int width, int height, QImage::Format fmt) : QImage(width, height, fmt) {
4765  refcount = 0;
4766  }
4767 
4768  lives_painter_surface_t (uint8_t *data, lives_painter_format_t fmt, int width, int height, int stride)
4769  : QImage(data,width,height,stride,fmt,imclean,(livespointer)data) {
4770  refcount = 0;
4771  }
4772 
4773 };
4774 
4775 
4776 boolean lives_painter_surface_destroy(lives_painter_surface_t *);
4777 
4778 
4779 class lives_painter_t : public QPainter {
4780 public:
4781  QPainterPath *p;
4782  lives_painter_surface_t *target;
4783  QPen pen;
4784 
4785 
4786  lives_painter_t(QWidget *widget) : QPainter(widget) {
4787  init();
4788  };
4789 
4790 
4791  lives_painter_t(lives_painter_surface_t *surf) : QPainter() {
4792  init();
4793  target = surf;
4794  };
4795 
4796 
4797  ~lives_painter_t() {
4798  if (target!=NULL) lives_painter_surface_destroy(target);
4799  delete p;
4800  }
4801 
4802 
4803 private:
4804 
4805  void init(void) {
4806  p = new QPainterPath();
4807  pen = QPen();
4808  target = NULL;
4809  }
4810 
4811 
4812 };
4813 
4814 
4815 #define LIVES_PAINTER_CONTENT_COLOR 0
4816 
4817 typedef QPainter::CompositionMode lives_painter_operator_t;
4818 
4819 #define LIVES_PAINTER_OPERATOR_UNKNOWN QPainter::CompositionMode_SourceOver
4820 #define LIVES_PAINTER_OPERATOR_DEFAULT QPainter::CompositionMode_SourceOver
4821 
4822 #define LIVES_PAINTER_OPERATOR_DEST_OUT QPainter::CompositionMode_DestinationOut
4823 
4824 #define LIVES_PAINTER_OPERATOR_DIFFERENCE QPainter::CompositionMode_Difference
4825 #define LIVES_PAINTER_OPERATOR_OVERLAY QPainter::CompositionMode_Overlay
4826 
4827 typedef Qt::FillRule lives_painter_fill_rule_t;
4828 
4829 #define LIVES_PAINTER_FILL_RULE_WINDING Qt::WindingFill
4830 #define LIVES_PAINTER_FILL_RULE_EVEN_ODD Qt::OddEvenFill
4831 
4832 
4833 #ifdef GUI_QT
4834 
4835 void LingoLayout::get_size(int *bwidth, int *bheight, int pwidth, int pheight) {
4836  QPainter qp;
4837  QRect rect = qp.boundingRect(0, 0, pwidth, pheight, Qt::AlignLeft | Qt::AlignTop, text);
4838  *bwidth = rect.width();
4839  *bheight = rect.height();
4840 }
4841 
4842 
4843 void LingoLayout::render_text(lives_painter_t *painter) {
4844  painter->drawText(x, y, width, height, align, text);
4845 }
4846 
4847 #endif
4848 
4849 
4850 #endif
4851 
4852 #include "moc_widget-helper-qt.cpp"
4853 
4854 
4855 #endif
LIVES_INLINE LiVESWidgetColor * lives_widget_color_copy(LiVESWidgetColor *c1, const LiVESWidgetColor *c2)
Definition: widget-helper.c:958
#define lives_free(a)
Definition: support.h:14
ulong lives_signal_connect(LiVESWidget *widget, const char *signal_name, ulong funcptr, livespointer data)
int boolean
Definition: videoplugin.h:50
#define lives_strdup(a)
Definition: support.h:13
Definition: main.h:277
#define ulong_random()
Definition: widget-helper.h:30
#define dgettext(Domain, Message)
Definition: support.h:39
#define dngettext(Domain, Message, MsgPlur, n)
Definition: support.h:40
#define TRUE
Definition: videoplugin.h:55
#define LIVES_INLINE
Definition: main.h:242
LIVES_INLINE uint32_t lives_timer_add(uint32_t interval, LiVESWidgetSourceFunc function, livespointer data)
Definition: widget-helper.c:6877
LIVES_INLINE boolean lives_container_remove(LiVESContainer *container, LiVESWidget *widget)
Definition: widget-helper.c:3640
LIVES_INLINE boolean lives_painter_surface_destroy(lives_painter_surface_t *surf)
Definition: widget-helper.c:150
#define FALSE
Definition: videoplugin.h:56