Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

QtGUI.php

Go to the documentation of this file.
00001 #!/usr/local/php512/bin/php
00002 <?
00003 /***************************************************************************
00004  *   Copyright (C) 2005 by Ferenc Veres   *
00005  *   lion@netngine.hu   *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 if(empty($argc))
00023 {
00024         exit;
00025 }
00026 include_once('QtBackend.php');
00027 
00028 if(!extension_loaded('php_qt')) {
00029         dl('php_qt.so');
00030 }
00031 
00032 class MainWindow extends QWidget
00033 {
00034         // Main window stuff
00035         public $layMain;        // Vertical layout
00036 
00037         // Translator text controls
00038         public $txtOriginal;
00039         public $txtTranslation;
00040         public $lblOriginal;
00041         public $lblTranslation;
00042 
00043         // Translator buttons
00044         public $btnQuit;
00045         public $btnPrev;
00046         public $btnNext;
00047         public $btnOKNext;
00048         public $wButtons;       // Placholder for translator buttons.
00049         public $layButtons;
00050 
00051         // Guess controls
00052         public $sldPercent;
00053         public $lcdPercent;
00054         public $btnRefresh;
00055         public $wGuessControls; // Placholder for guess controls.
00056         public $layGuessControls;
00057 
00058         // Guess text fields
00059         public $txtGuessPercents;
00060         public $txtGuessOriginals;
00061         public $txtGuessTranslations;
00062         public $btnGuessTake;
00063         public $layGrid;
00064 
00065         function __construct()
00066         {
00067                 parent::__construct();
00068 
00069                 $this->resize(600,500);
00070                 $maxGuesses = 9;
00071 
00072                 $this->layMain = new QVBoxLayout($this);
00073 
00074                 // Translator input fields
00075                 $this->txtOriginal = new QLineEdit("This will be the place for the English text.", $this);
00076                 $this->layMain->addWidget($this->txtOriginal);
00077                 //$mystr = new QString("alma");
00078                 //$this->lblOriginal = new QLabel("hello", $this);
00079                 //$this->lblOriginal = new QLabel($this);
00080                 //$this->lblOriginal = new QLabel($mystr, $this);
00081                 //$this->lblOriginal->setText("helllo");
00082                 //print_r($this->lblOriginal);
00083                 //$this->layMain->addWidget($this->lblOriginal);
00084 
00085                 $this->txtTranslation = new QLineEdit("Translation comes here", $this);
00086                 $this->layMain->addWidget($this->txtTranslation);
00087 
00088                 // Translator buttons
00089                 $this->wButtons = new QWidget();
00090                 $this->layButtons = new QHBoxLayout($this->wButtons);
00091                 $this->wButtons->setLayout($this->layButtons);
00092                 
00093                 $this->btnOKNext = new QPushButton("OK + Next", $this->wButtons);
00094                 $this->layButtons->addWidget($this->btnOKNext);
00095 
00096                 $this->btnPrev = new QPushButton("Previous", $this->wButtons);
00097                 $this->layButtons->addWidget($this->btnPrev);
00098                 
00099                 $this->btnNext = new QPushButton("Next", $this->wButtons);
00100                 $this->layButtons->addWidget($this->btnNext);
00101 
00102                 $this->layButtons->addStretch(1);
00103 
00104                 $this->btnQuit = new QPushButton("Quit", $this->wButtons);
00105                 $this->layButtons->addWidget($this->btnQuit);
00106                 
00107                 // Events for translator buttons
00108                 $this->connect($this->btnQuit, SIGNAL("clicked()"), QApplication::instance(), SLOT("quit()"));
00109                 $this->connect($this->btnNext, SIGNAL("clicked()"), $this, SLOT("btnNext_Clicked()"));
00110                 //$this->connect($this->btnNext, SIGNAL("clicked()"), QApplication::instance(), SLOT("aboutQt()"));
00111 
00112                 // Guess controls
00113                 $this->wGuessControls = new QWidget();
00114                 $this->sldPercent = new QSlider($this->wGuessControls);
00115                 $this->sldPercent->setOrientation(QT_ORIENTATIONS_HORIZONTAL);
00116                 $this->sldPercent->setRange(0, 99);
00117                 $this->sldPercent->setValue(50);
00118                 $this->lcdPercent = new QLCDNumber(2, $this->wGuessControls);
00119                 $this->lcdPercent->value(50);
00120                 $this->btnRefresh = new QPushButton("Refresh", $this->wGuessControls);
00121 
00122                 // Layout guess controls
00123                 $this->layGuessControls = new QHBoxLayout($this->wGuessControls);
00124                 $this->layGuessControls->addWidget($this->sldPercent);
00125                 $this->layGuessControls->addWidget($this->lcdPercent);
00126                 $this->layGuessControls->addWidget($this->btnRefresh);
00127 
00128                 $this->layGrid = new QGridLayout();
00129                 // Guess fields
00130                 for($i = 0; $i < $maxGuesses; $i++)
00131                 {
00132                         // Guess fields widgets
00133                         $this->txtGuessPercents[$i] = new QLineEdit("", $this);
00134                         $this->txtGuessOriginals[$i] = new QLineEdit("", $this);
00135                         $this->txtGuessTranslations[$i] = new QLineEdit("", $this);
00136                         $this->btnGuessTake[$i] = new QPushButton("^", $this);
00137 
00138                         // Guess fields layout
00139                         $this->layGrid->addWidget($this->txtGuessPercents[$i], $i, 0, 0);
00140                         $this->layGrid->addWidget($this->txtGuessOriginals[$i], $i, 1, 0);
00141                         $this->layGrid->addWidget($this->txtGuessTranslations[$i], $i, 2, 0);
00142                         $this->layGrid->addWidget($this->btnGuessTake[$i], $i, 3, 0);
00143                 }
00144 
00145                 // Event connections
00146                 $this->connect($this->sldPercent, SIGNAL("valueChanged(int)"),$this->lcdPercent, SLOT("display(int)"));
00147 
00148                 $this->layMain->addWidget($this->wButtons);
00149                 $this->layMain->addLayout($this->layGrid);
00150                 $this->layMain->addWidget($this->wGuessControls);
00151 
00152 
00153                 $this->setLayout($this->layMain);
00154 
00155                 $this->JustTest();
00156         }
00157 
00158         function btnNext_Clicked()
00159         {
00160                 echo "here we go";
00161                 QApplication::instance()->aboutQt();
00162                 //$this->Application->aboutQt();
00163         }
00164 
00165         function JustTest()
00166         {
00167         
00168                 $findText = "Delete All";
00169                 $filterPercent = 60;
00170         
00171                 //echo("SEEK: $findText\n");
00172                 // Upload this sentence to our $Sentence class
00173                 $str = new TranslationString();
00174                 $translations = $str->FindSimilar($findText, $filterPercent);
00175         
00176                 if(empty($translations))
00177                 {
00178                         echo("nothing similar, sorry.\n");
00179                         return;
00180                 }
00181                 
00182                 $i = 0;
00183                 foreach($translations as $id => $tr)
00184                 {
00185                         foreach($tr["strings"] as $key => $str)
00186                         {
00187                                 //echo($tr["percent"]."%\n");
00188                                 //echo("   >>> '".$str->GetOriginal()."' === '".$str->GetTranslation()."'\n");
00189                                 if($i < 9)
00190                                 {
00191                                         $this->txtGuessPercents[$i]->setText($tr["percent"]."%");
00192                                         //echo $this->txtGuessPercents[$i]->$text;
00193                                         $this->txtGuessOriginals[$i]->setText($str->GetOriginal());
00194                                         //$txt = new QString($str->GetTranslation());
00195                                         //echo "NA:".$txt->toUtf8();
00196                                         //$txt = new QString("aa");
00197                                         //$txt->toUtf8();
00198                                         //$this->txtGuessTranslations[$i]->setText($txt);
00199                                         $this->txtGuessTranslations[$i]->setText($str->GetTranslation());
00200                                 }
00201                                 $i++;
00202                         }
00203                 }
00204 
00205         }
00206 
00207 }
00208 
00209 
00210 $app = new QApplication();
00211 $widget = new MainWindow();
00212 $widget->show();
00213 
00214 $app->exec();
00215 
00216 ?>

Generated on Sat Apr 22 16:49:54 2006 for XarayaTranslationMemory by  doxygen 1.4.4