From 90825e2392b2d70e43c7a25b8a3752299a933894 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- .../rubylib/designer/examples/colortool/Makefile | 30 + qtruby/rubylib/designer/examples/colortool/README | 8 + .../designer/examples/colortool/colornameform.ui | 168 ++++++ .../examples/colortool/colornameform.ui.rb | 19 + .../designer/examples/colortool/findform.ui | 141 +++++ .../designer/examples/colortool/findform.ui.rb | 11 + .../designer/examples/colortool/images/editcopy | Bin 0 -> 268 bytes .../examples/colortool/images/editcopy.png | Bin 0 -> 187 bytes .../designer/examples/colortool/images/editcut | Bin 0 -> 214 bytes .../designer/examples/colortool/images/editcut.png | Bin 0 -> 179 bytes .../examples/colortool/images/editraise.png | Bin 0 -> 489 bytes .../designer/examples/colortool/images/filenew | Bin 0 -> 184 bytes .../designer/examples/colortool/images/filenew.png | Bin 0 -> 128 bytes .../designer/examples/colortool/images/fileopen | Bin 0 -> 231 bytes .../examples/colortool/images/fileopen.png | Bin 0 -> 178 bytes .../designer/examples/colortool/images/filesave | Bin 0 -> 230 bytes .../examples/colortool/images/filesave.png | Bin 0 -> 158 bytes .../examples/colortool/images/iconview.png | Bin 0 -> 898 bytes .../examples/colortool/images/richtextedit.png | Bin 0 -> 878 bytes .../designer/examples/colortool/images/searchfind | Bin 0 -> 658 bytes .../examples/colortool/images/searchfind.png | Bin 0 -> 554 bytes .../designer/examples/colortool/images/table.png | Bin 0 -> 407 bytes .../examples/colortool/images/tabwidget.png | Bin 0 -> 545 bytes .../examples/colortool/images/widgetstack.png | Bin 0 -> 664 bytes qtruby/rubylib/designer/examples/colortool/main.rb | 20 + .../designer/examples/colortool/mainform.ui | 601 +++++++++++++++++++++ .../designer/examples/colortool/mainform.ui.rb | 530 ++++++++++++++++++ .../designer/examples/colortool/optionsform.ui | 153 ++++++ 28 files changed, 1681 insertions(+) create mode 100644 qtruby/rubylib/designer/examples/colortool/Makefile create mode 100644 qtruby/rubylib/designer/examples/colortool/README create mode 100644 qtruby/rubylib/designer/examples/colortool/colornameform.ui create mode 100644 qtruby/rubylib/designer/examples/colortool/colornameform.ui.rb create mode 100644 qtruby/rubylib/designer/examples/colortool/findform.ui create mode 100644 qtruby/rubylib/designer/examples/colortool/findform.ui.rb create mode 100644 qtruby/rubylib/designer/examples/colortool/images/editcopy create mode 100644 qtruby/rubylib/designer/examples/colortool/images/editcopy.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/editcut create mode 100644 qtruby/rubylib/designer/examples/colortool/images/editcut.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/editraise.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/filenew create mode 100644 qtruby/rubylib/designer/examples/colortool/images/filenew.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/fileopen create mode 100644 qtruby/rubylib/designer/examples/colortool/images/fileopen.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/filesave create mode 100644 qtruby/rubylib/designer/examples/colortool/images/filesave.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/iconview.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/richtextedit.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/searchfind create mode 100644 qtruby/rubylib/designer/examples/colortool/images/searchfind.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/table.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/tabwidget.png create mode 100644 qtruby/rubylib/designer/examples/colortool/images/widgetstack.png create mode 100644 qtruby/rubylib/designer/examples/colortool/main.rb create mode 100644 qtruby/rubylib/designer/examples/colortool/mainform.ui create mode 100644 qtruby/rubylib/designer/examples/colortool/mainform.ui.rb create mode 100644 qtruby/rubylib/designer/examples/colortool/optionsform.ui (limited to 'qtruby/rubylib/designer/examples/colortool') diff --git a/qtruby/rubylib/designer/examples/colortool/Makefile b/qtruby/rubylib/designer/examples/colortool/Makefile new file mode 100644 index 00000000..df79b963 --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/Makefile @@ -0,0 +1,30 @@ +RBUIC=rbuic + +RBUICIMPLS=mainform.rb optionsform.rb colornameform.rb \ + findform.rb qmake_image_collection.rb + +all: $(RBUICIMPLS) + +mainform.rb: + $(RBUIC) mainform.ui -o mainform.rb + +optionsform.rb: optionsform.ui + $(RBUIC) optionsform.ui -o optionsform.rb + +colornameform.rb: colornameform.ui + $(RBUIC) colornameform.ui -o colornameform.rb + +findform.rb: findform.ui + $(RBUIC) findform.ui -o findform.rb + +qmake_image_collection.rb: + $(RBUIC) -embed colortool images/filenew.png images/fileopen.png \ + images/filesave.png images/editcut.png images/editcopy.png \ + images/searchfind.png images/tabwidget.png images/table.png \ + images/iconview.png images/richtextedit.png images/widgetstack.png \ + images/editraise.png -o qmake_image_collection.rb + +clean: + rm -f $(RBUICIMPLS) + + diff --git a/qtruby/rubylib/designer/examples/colortool/README b/qtruby/rubylib/designer/examples/colortool/README new file mode 100644 index 00000000..99d2174b --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/README @@ -0,0 +1,8 @@ +This is the Qt Designer Tutorial 'Creating Dialogs' translated into QtRuby. It +shows how you can combine ruby code generated from .ui files with the rbuic +tool, with your own code. + +The .ui files and images are identical to the original C++ versions. + +It features a simple Makefile to run rbuic when you change the .ui files, and +regenerate the ruby sources. diff --git a/qtruby/rubylib/designer/examples/colortool/colornameform.ui b/qtruby/rubylib/designer/examples/colortool/colornameform.ui new file mode 100644 index 00000000..50f2d6de --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/colornameform.ui @@ -0,0 +1,168 @@ + +ColorNameForm + + + ColorNameForm + + + + 0 + 0 + 348 + 105 + + + + Color Tool - Color Name + + + + unnamed + + + + colorLabel + + + + 80 + 0 + + + + + + + editraise.png + + + true + + + + + Layout4 + + + + unnamed + + + + Layout1 + + + + unnamed + + + + TextLabel2 + + + &Name: + + + colorLineEdit + + + + + colorLineEdit + + + + + + + Spacer2 + + + Vertical + + + Expanding + + + + 20 + 0 + + + + + + Layout4 + + + + unnamed + + + + Spacer3 + + + Horizontal + + + Expanding + + + + 0 + 11 + + + + + + okPushButton + + + &OK + + + true + + + + + cancelPushButton + + + &Cancel + + + + + + + + + + + cancelPushButton + clicked() + ColorNameForm + reject() + + + okPushButton + clicked() + ColorNameForm + validate() + + + + colornameform.ui.h + + + validate() + + + setColors( const QMap<QString, QColor> & colors ) + + + + diff --git a/qtruby/rubylib/designer/examples/colortool/colornameform.ui.rb b/qtruby/rubylib/designer/examples/colortool/colornameform.ui.rb new file mode 100644 index 00000000..db671b77 --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/colornameform.ui.rb @@ -0,0 +1,19 @@ +class ColorNameForm + +@colors = {} + +def setColors( colors ) + @colors = colors +end + +def validate() + name = @colorLineEdit.text() + if ! name.empty? && + ( @colors.empty? || ! @colors.has_key?( name ) ) + accept() + else + @colorLineEdit.selectAll() + end +end + +end diff --git a/qtruby/rubylib/designer/examples/colortool/findform.ui b/qtruby/rubylib/designer/examples/colortool/findform.ui new file mode 100644 index 00000000..3e627945 --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/findform.ui @@ -0,0 +1,141 @@ + +FindForm + + + FindForm + + + + 0 + 0 + 301 + 99 + + + + Color Tool - Find Color + + + + unnamed + + + + Layout11 + + + + unnamed + + + + TextLabel3 + + + &Look for: + + + findLineEdit + + + + + findLineEdit + + + + + + + Spacer4 + + + Vertical + + + Expanding + + + + 20 + 0 + + + + + + Layout10 + + + + unnamed + + + + Spacer7 + + + Horizontal + + + Expanding + + + + 0 + 9 + + + + + + findPushButton + + + &Find + + + true + + + + + closePushButton + + + &Close + + + + + + + + + closePushButton + clicked() + FindForm + accept() + + + findPushButton + clicked() + FindForm + find() + + + + findform.ui.h + + + lookfor(const QString&) + + + find() + + + notfound() + + + + diff --git a/qtruby/rubylib/designer/examples/colortool/findform.ui.rb b/qtruby/rubylib/designer/examples/colortool/findform.ui.rb new file mode 100644 index 00000000..6bfb4f0a --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/findform.ui.rb @@ -0,0 +1,11 @@ +class FindForm + +def find() + emit lookfor( @findLineEdit.text() ) +end + +def notfound() + @findLineEdit.selectAll() +end + +end diff --git a/qtruby/rubylib/designer/examples/colortool/images/editcopy b/qtruby/rubylib/designer/examples/colortool/images/editcopy new file mode 100644 index 00000000..7b334ca4 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/editcopy differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/editcopy.png b/qtruby/rubylib/designer/examples/colortool/images/editcopy.png new file mode 100644 index 00000000..abfe86e2 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/editcopy.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/editcut b/qtruby/rubylib/designer/examples/colortool/images/editcut new file mode 100644 index 00000000..60abc586 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/editcut differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/editcut.png b/qtruby/rubylib/designer/examples/colortool/images/editcut.png new file mode 100644 index 00000000..98efe27a Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/editcut.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/editraise.png b/qtruby/rubylib/designer/examples/colortool/images/editraise.png new file mode 100644 index 00000000..02415689 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/editraise.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/filenew b/qtruby/rubylib/designer/examples/colortool/images/filenew new file mode 100644 index 00000000..9de6e839 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/filenew differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/filenew.png b/qtruby/rubylib/designer/examples/colortool/images/filenew.png new file mode 100644 index 00000000..8577f068 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/filenew.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/fileopen b/qtruby/rubylib/designer/examples/colortool/images/fileopen new file mode 100644 index 00000000..a21f9466 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/fileopen differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/fileopen.png b/qtruby/rubylib/designer/examples/colortool/images/fileopen.png new file mode 100644 index 00000000..85dab435 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/fileopen.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/filesave b/qtruby/rubylib/designer/examples/colortool/images/filesave new file mode 100644 index 00000000..f6d9af92 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/filesave differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/filesave.png b/qtruby/rubylib/designer/examples/colortool/images/filesave.png new file mode 100644 index 00000000..21309aa6 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/filesave.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/iconview.png b/qtruby/rubylib/designer/examples/colortool/images/iconview.png new file mode 100644 index 00000000..d755399d Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/iconview.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/richtextedit.png b/qtruby/rubylib/designer/examples/colortool/images/richtextedit.png new file mode 100644 index 00000000..9f75c258 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/richtextedit.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/searchfind b/qtruby/rubylib/designer/examples/colortool/images/searchfind new file mode 100644 index 00000000..7aaefe22 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/searchfind differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/searchfind.png b/qtruby/rubylib/designer/examples/colortool/images/searchfind.png new file mode 100644 index 00000000..8f7d8adb Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/searchfind.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/table.png b/qtruby/rubylib/designer/examples/colortool/images/table.png new file mode 100644 index 00000000..663b32f0 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/table.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/tabwidget.png b/qtruby/rubylib/designer/examples/colortool/images/tabwidget.png new file mode 100644 index 00000000..3a160446 Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/tabwidget.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/images/widgetstack.png b/qtruby/rubylib/designer/examples/colortool/images/widgetstack.png new file mode 100644 index 00000000..979409cf Binary files /dev/null and b/qtruby/rubylib/designer/examples/colortool/images/widgetstack.png differ diff --git a/qtruby/rubylib/designer/examples/colortool/main.rb b/qtruby/rubylib/designer/examples/colortool/main.rb new file mode 100644 index 00000000..9ebe84cb --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/main.rb @@ -0,0 +1,20 @@ +require 'Qt' + +require 'mainform.rb' +require 'mainform.ui.rb' + +require 'colornameform.rb' +require 'colornameform.ui.rb' + +require 'optionsform.rb' + +require 'findform.rb' +require 'findform.ui.rb' + +require 'qmake_image_collection.rb' + +a = Qt::Application.new(ARGV) +w = MainForm.new +a.mainWidget = w +w.show +a.exec diff --git a/qtruby/rubylib/designer/examples/colortool/mainform.ui b/qtruby/rubylib/designer/examples/colortool/mainform.ui new file mode 100644 index 00000000..6c89baca --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/mainform.ui @@ -0,0 +1,601 @@ + +MainForm + + + MainForm + + + + 0 + 0 + 600 + 480 + + + + Color Tool + + + + unnamed + + + + colorWidgetStack + + + NoFrame + + + Plain + + + + tablePage + + + 0 + + + + unnamed + + + + + Name + + + + + Hex + + + + + Web + + + + colorTable + + + 0 + + + 3 + + + true + + + + + + + iconsPage + + + 1 + + + + unnamed + + + + colorIconView + + + 100 + + + Adjust + + + + + + + + + + menubar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + toolBar + + + Tools + + + + + + + + + + + + + + + + + + + + fileNewAction + + + filenew.png + + + New + + + &New + + + Ctrl+N + + + + + fileOpenAction + + + fileopen.png + + + Open + + + &Open... + + + Ctrl+O + + + + + fileSaveAction + + + filesave.png + + + Save + + + &Save + + + Ctrl+S + + + + + fileSaveAsAction + + + Save As + + + Save &As... + + + + + + + + fileExitAction + + + Exit + + + E&xit + + + + + + + + editCutAction + + + editcut.png + + + Delete + + + &Delete + + + Ctrl+X + + + + + editCopyAction + + + editcopy.png + + + Copy + + + &Copy + + + Ctrl+C + + + + + editFindAction + + + searchfind.png + + + Find + + + &Find... + + + Ctrl+F + + + + + helpContentsAction + + + Contents + + + &Contents... + + + + + + + + helpIndexAction + + + Index + + + &Index... + + + + + + + + helpAboutAction + + + About + + + &About + + + + + + + + optionsAction + + + tabwidget.png + + + Options + + + &Options... + + + + + viewActionGroup + + + View + + + View + + + false + + + + viewTableAction + + + true + + + true + + + table.png + + + View Table + + + View &Table + + + View Table (Ctrl+T) + + + Ctrl+T + + + + + viewIconsAction + + + true + + + iconview.png + + + View Icons + + + View &Icons + + + View Icons (Ctrl+I) + + + Ctrl+I + + + + + + editAddAction + + + widgetstack.png + + + Add + + + &Add... + + + Ctrl+A + + + + + + fileNewAction + activated() + MainForm + fileNew() + + + fileOpenAction + activated() + MainForm + fileOpen() + + + fileSaveAction + activated() + MainForm + fileSave() + + + fileSaveAsAction + activated() + MainForm + fileSaveAs() + + + fileExitAction + activated() + MainForm + fileExit() + + + editCutAction + activated() + MainForm + editCut() + + + editCopyAction + activated() + MainForm + editCopy() + + + editFindAction + activated() + MainForm + editFind() + + + helpIndexAction + activated() + MainForm + helpIndex() + + + helpContentsAction + activated() + MainForm + helpContents() + + + helpAboutAction + activated() + MainForm + helpAbout() + + + colorTable + currentChanged(int,int) + MainForm + changedTableColor(int,int) + + + colorIconView + currentChanged(QIconViewItem*) + MainForm + changedIconColor(QIconViewItem*) + + + viewActionGroup + selected(QAction*) + MainForm + changeView(QAction*) + + + editAddAction + activated() + MainForm + editAdd() + + + optionsAction + activated() + MainForm + editOptions() + + + colorWidgetStack + aboutToShow(int) + MainForm + aboutToShow() + + + + findform.h + qsettings.h + qradiobutton.h + qcheckbox.h + colornameform.h + qcolordialog.h + qregexp.h + qfile.h + qfiledialog.h + qapplication.h + qcolor.h + qstring.h + qpainter.h + qstatusbar.h + qmessagebox.h + qclipboard.h + qlabel.h + qlineedit.h + optionsform.h + mainform.ui.h + + + class QString; + class QColor; + + + QStringList m_comments; + QString m_filename; + bool m_changed; + bool m_table_dirty; + bool m_icons_dirty; + int m_clip_as; + bool m_show_web; + QClipboard *clipboard; + FindForm *findForm; + QMap<QString,QColor> m_colors; + + + fileNew() + fileOpen() + fileSave() + fileSaveAs() + closeEvent( QCloseEvent * ) + fileExit() + editCut() + editCopy() + editFind() + lookfor( const QString & text ) + helpIndex() + helpContents() + helpAbout() + changedTableColor( int row, int ) + changedIconColor( QIconViewItem * item ) + changeView( QAction * action ) + editAdd() + editOptions() + aboutToShow() + + + init() + clearData( bool fillWithDefaults ) + populate() + colorSwatch( const QColor color ) + load( const QString & filename ) + okToClear() + changedColor( const QString & name ) + isWebColor( QColor color ) + loadSettings() + saveSettings() + + + + diff --git a/qtruby/rubylib/designer/examples/colortool/mainform.ui.rb b/qtruby/rubylib/designer/examples/colortool/mainform.ui.rb new file mode 100644 index 00000000..471233bd --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/mainform.ui.rb @@ -0,0 +1,530 @@ +class MainForm + + CLIP_AS_HEX = 0 + CLIP_AS_NAME = 1 + CLIP_AS_RGB = 2 + COL_NAME = 0 + COL_HEX = 1 + COL_WEB = 2 + WINDOWS_REGISTRY = "/QtExamples" + APP_KEY = "/ColorTool/" + +def init() + @clipboard = Qt::Application.clipboard() + if @clipboard.supportsSelection() + @clipboard.selectionMode = true + end + + findForm = 0 + loadSettings() + @filename = nil + @changed = false + @table_dirty = true + @icons_dirty = true + @colors = {} + @comments = {} + clearData( true ) +end + +def clearData( fillWithDefaults ) + setCaption( "Color Tool" ) + + @colors.clear() + @comments.clear() + + if fillWithDefaults + @colors["black"] = Qt::black + @colors["blue"] = Qt::blue + @colors["cyan"] = Qt::cyan + @colors["darkblue"] = Qt::darkBlue + @colors["darkcyan"] = Qt::darkCyan + @colors["darkgray"] = Qt::darkGray + @colors["darkgreen"] = Qt::darkGreen + @colors["darkmagenta"] = Qt::darkMagenta + @colors["darkred"] = Qt::darkRed + @colors["darkyellow"] = Qt::darkYellow + @colors["gray"] = Qt::gray + @colors["green"] = Qt::green + @colors["lightgray"] = Qt::lightGray + @colors["magenta"] = Qt::magenta + @colors["red"] = Qt::red + @colors["white"] = Qt::white + @colors["yellow"] = Qt::yellow + end + + populate() +end + +def populate() + if @table_dirty + (0...@colorTable.numRows).each do |r| + (0...@colorTable.numCols).each do |c| + @colorTable.clearCell( r, c ) + end + end + + @colorTable.numRows = @colors.length + if ! @colors.empty? + pixmap = Qt::Pixmap.new( 22, 22 ) + row = 0 + @colors.sort.each do |pair| + key = pair[0] + color = pair[1] + pixmap.fill( color ) + @colorTable.setText( row, COL_NAME, key ) + @colorTable.setPixmap( row, COL_NAME, pixmap ); + @colorTable.setText( row, COL_HEX, color.name().upcase() ) + if @show_web + item = Qt::CheckTableItem.new( @colorTable, "" ) + item.checked = webColor?( color ) + @colorTable.setItem( row, COL_WEB, item ) + end + row += 1 + end + @colorTable.setCurrentCell( 0, 0 ) + end + @colorTable.adjustColumn( COL_NAME ) + @colorTable.adjustColumn( COL_HEX ) + if @show_web + @colorTable.showColumn( COL_WEB ) + @colorTable.adjustColumn( COL_WEB ) + else + @colorTable.hideColumn( COL_WEB ) + end + @table_dirty = FALSE; + end + + if @icons_dirty + @colorIconView.clear() + + @colors.each do |key, data| + Qt::IconViewItem.new( @colorIconView, key, colorSwatch(data) ) + end + @icons_dirty = false + end +end + +def colorSwatch( color ) + pixmap = Qt::Pixmap.new( 80, 80 ) + pixmap.fill( white ) + painter = Qt::Painter.new + painter.begin( pixmap ) + painter.pen = NoPen + painter.brush = color + painter.drawEllipse( 0, 0, 80, 80 ) + painter.end() + return pixmap +end + +def fileNew() + if okToClear() + @filename = nil + @changed = false + @table_dirty = true + @icons_dirty = true + clearData( false ) + end +end + +def fileOpen() + if ! okToClear() + return + end + + filename = Qt::FileDialog.getOpenFileName( + nil, "Colors (*.txt)", self, + "file open", "Color Tool -- File Open" ) + if ! filename.nil? + load( filename ) + else + statusBar().message( "File Open abandoned", 2000 ) + end +end + +def fileSave() + if @filename.nil? + fileSaveAs() + return + end + + file = Qt::File.new( @filename ) + if file.open( Qt::IO_WriteOnly ) + stream = Qt::TextStream.new( file ) + if ! @comments.empty? + stream << @comments + "\n" << "\n" + end + + @colors.each do |key, color| + stream << "%3d %3d %3d \t\t#{key}" % [color.red, color.green, color.blue] << "\n" + end + file.close() + setCaption( "Color Tool -- #{@filename}" ) + statusBar().message( "Saved #{@colors.length} colors to '#{@filename}'", 3000 ) + @changed = false; + else + statusBar().message( "Failed to save '#{@filename}'", 3000 ) + end +end + +def fileSaveAs() + filename = Qt::FileDialog.getSaveFileName( + nil, "Colors (*.txt)", self, + "file save as", "Color Tool -- File Save As" ) + if ! filename.nil? + ans = 0 + if Qt::File.exists( filename ) + ans = Qt::MessageBox.warning( + self, "Color Tool -- Overwrite File", + "Overwrite\n'#{filename}'?" , + "&Yes", "&No", nil, 1, 1 ) + end + if ans == 0 + @filename = filename + fileSave() + return + end + end + statusBar().message( "Saving abandoned", 2000 ) +end + +def load( filename ) + clearData( false ) + @filename = filename + regex = Regexp.new( "^\\s*(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\S+.*)$" ) + file = Qt::File.new( filename ) + if file.open( Qt::IO_ReadOnly ) + statusBar().message( "Loading '#{filename}'..." ) + stream = Qt::TextStream.new( file ) + while ! stream.eof() + line = stream.readLine() + m = regex.match( line ) + if m.nil? + @comments += line + else + @colors[m[4]] = Qt::Color.new(m[1].to_i,m[2].to_i,m[3].to_i ) + end + end + file.close() + @filename = filename + setCaption( "Color Tool -- #{@filename}" ) + statusBar().message( "Loaded '#{@filename}'", 3000 ) + visible = @colorWidgetStack.visibleWidget() + @icons_dirty = ! ( @table_dirty = ( visible == @tablePage ) ) + populate() + @icons_dirty = ! ( @table_dirty = ( visible != @tablePage ) ) + @changed = false + else + statusBar().message( "Failed to load '#{@filename}'", 3000 ) + end +end + + +def okToClear() + if @changed + if @filename.nil? + msg = "Unnamed colors " + else + msg = "Colors '#{@filename}'\n" + end + msg += "has been changed." + ans = Qt::MessageBox.information( + self, + "Color Tool -- Unsaved Changes", + msg, "&Save", "Cancel", "&Abandon", + 0, 1 ) + if ans == 0 + fileSave() + elsif ans == 1 + return false + end + end + + return true +end + +def closeEvent( e ) + fileExit() +end + +def fileExit() + if okToClear() + saveSettings() + Qt::Application.exit( 0 ) + end +end + +def editCut() + visible = @colorWidgetStack.visibleWidget() + statusBar().message( "Deleting '#{name}'" ) + + if visible == @tablePage && @colorTable.numRows() > 0 + row = @colorTable.currentRow() + name = @colorTable.text( row, 0 ) + @colorTable.removeRow( @colorTable.currentRow() ) + if row < @colorTable.numRows() + @colorTable.setCurrentCell( row, 0 ) + elsif @colorTable.numRows() > 0 + @colorTable.setCurrentCell( @colorTable.numRows() - 1, 0 ) + end + @icons_dirty = true + elsif visible == @iconsPage && @colorIconView.currentItem() + item = colorIconView.currentItem() + name = item.text() + if @colorIconView.count() == 1 + @colorIconView.clear() + else + current = item.nextItem() + if ! current + current = item.prevItem() + end + item.dispose + if current + @colorIconView.currentItem = current + end + @colorIconView.arrangeItemsInGrid() + end + @table_dirty = true + end + + if ! name.nil? + @colors.delete( name ) + @changed = true + statusBar().message( "Deleted '#{name}'", 5000 ) + else + statusBar().message( "Failed to delete '#{name}'", 5000 ) + end +end + +def editCopy() + visible = @colorWidgetStack.visibleWidget() + + if visible == @tablePage && @colorTable.numRows() + row = @colorTable.currentRow() + text = @colorTable.text( row, 0 ) + elsif visible == @iconsPage && ! @colorIconView.currentItem().nil? + item = @colorIconView.currentItem() + text = item.text() + end + if ! text.nil? + color = @colors[text] + case @clip_as + when CLIP_AS_HEX then text = color.name() + when CLIP_AS_NAME then + when CLIP_AS_RGB + text = "#{color.red},#{color.green},#{color.blue}" + end + @clipboard.text = text + statusBar().message( "Copied '" + text + "' to the clipboard" ) + end +end + +def editFind() + if ! @findForm + @findForm = FindForm.new( self ) + connect( @findForm, SIGNAL( 'lookfor(const QString&)' ), + self, SLOT( 'lookfor(const QString&)' ) ) + end + @findForm.show() +end + +def lookfor( text ) + if text.empty? + return + end + ltext = text.downcase() + visible = colorWidgetStack.visibleWidget() + found = false + + if visible == @tablePage && @colorTable.numRows() > 0 + row = @colorTable.currentRow() + (row+1...@colorTable.numRows).each do |i| + if @colorTable.text( i, 0 ).downcase().include?( ltext ) + @colorTable.setCurrentCell( i, 0 ) + @colorTable.clearSelection() + @colorTable.selectRow( i ) + found = true + break + end + end + if ! found + @colorTable.setCurrentCell( row, 0 ) + end + elsif visible == @iconsPage + start = @colorIconView.currentItem() + item = start.nextItem() unless start.nil? + while !item.nil? + if item.text().downcase().include?( ltext ) + @colorIconView.currentItem = item + @colorIconView.ensureItemVisible( item ) + found = true + break + end + item = item.nextItem() + end + if ! found && !start.nil? + @colorIconView.currentItem = start + end + end + if ! found + statusBar().message( "Could not find '#{text}' after here" ) + @findForm.notfound() + end +end + + + +def helpIndex() +end + +def helpContents() +end + +def helpAbout() +end + + +def changedTableColor( row, i ) + changedColor( @colorTable.text( row, COL_NAME ) ) +end + +def changedIconColor( item ) + changedColor( item.text() ) +end + +def changedColor( name ) + color = @colors[name] + r = color.red() + g = color.green() + b = color.blue() + statusBar().message( "%s \"%s\" (%d,%d,%d) %s {%.3f %.3f %.3f}" % + [name, color.name.upcase, + r, g, b, webColor?( color ) ? ' web' : '', + r / 255.0, g / 255.0, b / 255.0] ) +end + +def changeView(action) + if action == @viewTableAction + @colorWidgetStack.raiseWidget( @tablePage ) + else + @colorWidgetStack.raiseWidget( @iconsPage ) + end +end + +def webColor?( color ) + r = color.red() + g = color.green() + b = color.blue() + + return ( ( r == 0 || r == 51 || r == 102 || + r == 153 || r == 204 || r == 255 ) && + ( g == 0 || g == 51 || g == 102 || + g == 153 || g == 204 || g == 255 ) && + ( b == 0 || b == 51 || b == 102 || + b == 153 || b == 204 || b == 255 ) ) +end + + +def editAdd() + color = Qt::white + if ! @colors.empty? + visible = @colorWidgetStack.visibleWidget() + if visible == @tablePage + color = Qt::Color.new(@colorTable.text( @colorTable.currentRow(), + @colorTable.currentColumn() )) + else + color = Qt::Color.new(@colorIconView.currentItem().text()) + end + end + color = Qt::ColorDialog.getColor( color, self ) + if color.valid? + pixmap = Qt::Pixmap.new( 80, 10 ) + pixmap.fill( color ) + colorForm = ColorNameForm.new( self, "color", true ) + colorForm.setColors( @colors ) + colorForm.colorLabel.setPixmap( pixmap ) + if colorForm.exec() + name = colorForm.colorLineEdit.text() + @colors[name] = color + pixmap = Qt::Pixmap.new( 22, 22 ) + pixmap.fill( color ) + row = @colorTable.currentRow() + @colorTable.insertRows( row, 1 ) + @colorTable.setText( row, COL_NAME, name ) + @colorTable.setPixmap( row, COL_NAME, pixmap ) + @colorTable.setText( row, COL_HEX, color.name().upcase() ) + if @show_web + item = Qt::CheckTableItem.new( @colorTable, "" ) + item.checked = webColor?( color ) + @colorTable.setItem( row, COL_WEB, item ) + end + @colorTable.setCurrentCell( row, 0 ) + + Qt::IconViewItem.new( @colorIconView, name, + colorSwatch( color ) ) + @changed = true + end + end +end + +def editOptions() + options = OptionsForm.new( self, "options", true ) + case @clip_as + when CLIP_AS_HEX + options.hexRadioButton.checked = true + when CLIP_AS_NAME + options.nameRadioButton.checked = true + when CLIP_AS_RGB + options.rgbRadioButton.checked = true + end + options.webCheckBox.checked = @show_web + + if options.exec() + if options.hexRadioButton.checked? + @clip_as = CLIP_AS_HEX + elsif options.nameRadioButton.checked? + @clip_as = CLIP_AS_NAME + elsif options.rgbRadioButton.checked? + @clip_as = CLIP_AS_RGB + end + @table_dirty = @show_web != options.webCheckBox.checked? + @show_web = options.webCheckBox.checked? + populate() + end +end + +def loadSettings() + settings = Qt::Settings.new + settings.insertSearchPath( Qt::Settings::Windows, WINDOWS_REGISTRY ) + windowWidth = settings.readNumEntry( APP_KEY + "WindowWidth", 550 ) + windowHeight = settings.readNumEntry( APP_KEY + "WindowHeight", 500 ) + windowX = settings.readNumEntry( APP_KEY + "WindowX", 0 ) + windowY = settings.readNumEntry( APP_KEY + "WindowY", 0 ) + @clip_as = settings.readNumEntry( APP_KEY + "ClipAs", CLIP_AS_HEX ) + @show_web = settings.readBoolEntry( APP_KEY + "ShowWeb", true ) + if ! settings.readBoolEntry( APP_KEY + "View", true ) + @colorWidgetStack.raiseWidget( @iconsPage ) + @viewIconsAction.on = true + end + + resize( windowWidth, windowHeight ) + move( windowX, windowY ) +end + +def saveSettings() + settings = Qt::Settings.new + settings.insertSearchPath( Qt::Settings::Windows, WINDOWS_REGISTRY ) + settings.writeEntry( APP_KEY + "WindowWidth", width() ) + settings.writeEntry( APP_KEY + "WindowHeight", height() ) + settings.writeEntry( APP_KEY + "WindowX", x() ) + settings.writeEntry( APP_KEY + "WindowY", y() ) + settings.writeEntry( APP_KEY + "ClipAs", @clip_as ) + settings.writeEntry( APP_KEY + "ShowWeb", @show_web ) + settings.writeEntry( APP_KEY + "View", @colorWidgetStack.visibleWidget() == @tablePage ) +end + + +def aboutToShow() + populate() +end + +end diff --git a/qtruby/rubylib/designer/examples/colortool/optionsform.ui b/qtruby/rubylib/designer/examples/colortool/optionsform.ui new file mode 100644 index 00000000..1bb7e8ef --- /dev/null +++ b/qtruby/rubylib/designer/examples/colortool/optionsform.ui @@ -0,0 +1,153 @@ + +OptionsForm + + + OptionsForm + + + + 0 + 0 + 306 + 226 + + + + Color Tool - Options + + + + unnamed + + + + GroupBox2 + + + Table View + + + + unnamed + + + + webCheckBox + + + Indicate &Web colors + + + true + + + + + + + ButtonGroup1 + + + Copy to Clipboard As + + + + unnamed + + + + hexRadioButton + + + &Hex, e.g. #AB347F + + + true + + + + + nameRadioButton + + + &Name, e.g. light blue + + + + + rgbRadioButton + + + &RGB, e.g. 51,255,102 + + + + + + + Layout5 + + + + unnamed + + + + Spacer2 + + + Horizontal + + + Expanding + + + + 0 + 10 + + + + + + okPushButton + + + &OK + + + true + + + + + cancelPushButton + + + &Cancel + + + + + + + + + okPushButton + clicked() + OptionsForm + accept() + + + cancelPushButton + clicked() + OptionsForm + reject() + + + + optionsform.ui.h + + + + -- cgit v1.2.3