MainWindow.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005 by Ferenc Veres   *
00004  *   lion@netngine.hu   *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00020  ***************************************************************************/
00021 if(empty($argc))
00022 {
00023         exit;
00024 }
00025 
00026 class MainWindow extends QWidget
00027 {
00028         public $backend;
00029         
00030         // Main window stuff
00031         public $vboxMain;       // Main vertical layout
00032         public $splitterMain;
00033         public $vboxWorkArea;
00034         public $vboxSearchArea;
00035         public $wWorkArea;
00036         public $wSearchArea;
00037 
00038         public $gridWorkFields;
00039         
00040         // Translator text controls
00041         public $lblLevelsLabel;
00042         public $lblLevels;
00043         public $lblOriginal;
00044         public $txtOriginal;
00045         public $lblTranslation;
00046         public $txtTranslation;
00047 
00048         // Translator buttons
00049         public $btnSaveNext;
00050         public $btnSaveNextMissing;
00051         public $btnSave;
00052         public $btnNext;
00053         public $btnNextMissing;
00054         public $btnSavePopStack;
00055         public $btnSaveToAllChecked;
00056         
00057         public $hboxButtons;// Placholder for translator buttons.
00058         
00059         public $btnQuit;
00060 
00061         // Search controls
00062         public $sldPercent;
00063         public $lcdPercent;
00064         public $btnRefresh;
00065         public $hboxSearchPercent; // Placholder for guess controls.
00066 
00067         // Search results
00068         public $tblSearchResults;
00069         public $hboxSearchFullView;
00070         public $lblSearchOriginalFull;
00071         public $lblSearchTranslationFull;
00072 
00073         // Project tree
00074         public $modelProjects;
00075         public $treeProjects;
00076 
00077         // Slots and Signals
00078         private $slots = array(
00079                 "tblSearchResults_DoubleClicked(int,int)",
00080                 "tblSearchResults_Clicked(int,int)",
00081                 "btnSave_Clicked()",
00082                 "btnSaveNext_Clicked()",
00083                 "btnSaveNextMissing_Clicked()",
00084                 "btnNext_Clicked()",
00085                 "btnNextMissing_Clicked()");
00086         private $signals = array("");
00087 
00088         // Misc private variables
00089         private $TableColumnsFixed;
00090         
00091         function __construct()
00092         {
00093                 parent::__construct();
00094 
00095                 $this->backend = new QtBackend($this);
00096                 $this->backend->xProjectID = 1;
00097                 $this->backend->xStringID = 0;
00098                 //$backend->EventHandler();
00099 
00100                 $this->resize(600,500);
00101 
00102                 $this->splitterMain = new QSplitter($this);
00103                 $this->splitterMain->setOrientation(Qt::Vertical);
00104                 
00105                 $this->vboxMain = new QVBoxLayout($this);
00106 
00107                 // Translator input fields
00108 
00109                 $this->gridWorkFields = new QGridLayout($this);
00110                 $this->gridWorkFields->setMargin(0);
00111                 
00112                 // Project path display
00113                 $this->lblLevelsLabel = new QLabel("Project Path:", $this);
00114                 $this->lblLevels = new QLabel("none", $this);
00115                 $this->gridWorkFields->addWidget($this->lblLevelsLabel, 0, 0);
00116                 $this->gridWorkFields->addWidget($this->lblLevels, 0, 1);
00117 
00118                 // Original string
00119                 $this->lblOriginal = new QLabel("Original", $this);
00120                 $this->txtOriginal = new QLabel("", $this);
00121                 $this->txtOriginal->setWordWrap(true);
00122                 //$this->txtOriginal->setTextFormat(Qt::PlainText);
00123                 $this->txtOriginal->setMinimumHeight(70);
00124                 $this->gridWorkFields->addWidget($this->lblOriginal, 1,0);
00125                 $this->gridWorkFields->addWidget($this->txtOriginal, 1,1);
00126                 
00127                 // Translaition field
00128                 $this->lblTranslation = new QLabel("Translation", $this);
00129                 $this->txtTranslation = new QTextEdit("", $this);
00130                 $this->txtOriginal->setMaximumHeight(70);
00131                 $this->gridWorkFields->addWidget($this->lblTranslation, 2,0);
00132                 $this->gridWorkFields->addWidget($this->txtTranslation, 2,1);
00133 
00134                 // Translator buttons
00135                 $this->hboxButtons = new QHBoxLayout($this);
00136                 $this->hboxButtons->setMargin(0);
00137                 
00138                 $this->btnSaveNext = new QPushButton("Save + Next", $this);
00139                 $this->hboxButtons->addWidget($this->btnSaveNext);
00140                 $this->btnSaveNextMissing = new QPushButton("Save + Next missing", $this);
00141                 $this->hboxButtons->addWidget($this->btnSaveNextMissing);
00142                 $this->btnSave = new QPushButton("Save", $this);
00143                 $this->hboxButtons->addWidget($this->btnSave);
00144                 $this->btnNext = new QPushButton("Next", $this);
00145                 $this->hboxButtons->addWidget($this->btnNext);
00146                 $this->btnNextMissing = new QPushButton("Next missing", $this);
00147                 $this->hboxButtons->addWidget($this->btnNextMissing);
00148                 $this->btnSavePopStack = new QPushButton("Save + Pop", $this);
00149                 $this->hboxButtons->addWidget($this->btnSavePopStack);
00150                 $this->btnSaveToAllChecked = new QPushButton("Save to all checked", $this);
00151                 $this->hboxButtons->addWidget($this->btnSaveToAllChecked);
00152                 $this->hboxButtons->addStretch(1);
00153                 $this->btnQuit = new QPushButton("Quit", $this);
00154                 $this->hboxButtons->addWidget($this->btnQuit);
00155 
00156                 // Search controls
00157                 $this->sldPercent = new QSlider($this);
00158                 $this->sldPercent->setOrientation(Qt::Horizontal);
00159                 $this->sldPercent->setRange(0, 99);
00160                 $this->sldPercent->setValue(50);
00161                 $this->lcdPercent = new QLCDNumber(2, $this);
00162                 $this->lcdPercent->value(50);
00163                 $this->btnRefresh = new QPushButton("Refresh", $this);
00164 
00165                 // Layout guess controls
00166                 $this->hboxSearchPercent = new QHBoxLayout($this);
00167                 $this->hboxSearchPercent->addWidget($this->sldPercent);
00168                 $this->hboxSearchPercent->addWidget($this->lcdPercent);
00169                 $this->hboxSearchPercent->addWidget($this->btnRefresh);
00170                 
00171                 // Full view of search entries
00172                 $this->hboxSearchFullView = new QHBoxLayout($this);
00173                 $this->lblSearchOriginalFull = new QLabel("1", $this);
00174                 $this->lblSearchOriginalFull->setMinimumHeight(70);
00175                 $this->lblSearchOriginalFull->setWordWrap(true);
00176                 $this->lblSearchTranslationFull = new QLabel("2", $this);
00177                 $this->lblSearchTranslationFull->setMinimumHeight(70);
00178                 $this->lblSearchTranslationFull->setWordWrap(true);
00179                 $this->hboxSearchFullView->addWidget($this->lblSearchOriginalFull);
00180                 $this->hboxSearchFullView->addWidget($this->lblSearchTranslationFull);
00181 
00182                 // Search results table
00183                 $this->tblSearchResults = new QTableWidget(0, 3, $this);
00184                 $this->tblSearchResults->setSelectionBehavior(1); //QAbstractItemView::SelectRows);
00185                 $this->tblSearchResults->setEditTriggers(0);
00186                 $this->tblSearchResults->setHorizontalHeaderItem(0,  new QTableWidgetItem(new QString("Match")));
00187                 $this->tblSearchResults->setHorizontalHeaderItem(1,  new QTableWidgetItem(new QString("Original string")));
00188                 $this->tblSearchResults->setHorizontalHeaderItem(2,  new QTableWidgetItem(new QString("Translated string")));
00189 
00190                 // Project tree
00191                 //$this->modelProjects = new ProjectTreeModel();
00192                 //$this->treeProjects = new QTreeView($this);
00193                 //$this->treeProjects->setModel($this->modelProjects);
00194 
00195                 //$this->vboxMain->addWidget($this->treeProjects);
00196 
00197                 $this->ConnectSignals();
00198                 
00199                 
00200                 // Add controls to the main layout
00201 
00202                 $this->wWorkArea = new QWidget();
00203                 $this->vboxWorkArea = new QVBoxLayout($this->wWorkArea);
00204 
00205                 $this->vboxWorkArea->addLayout($this->gridWorkFields);
00206                 $this->vboxWorkArea->addLayout($this->hboxButtons);
00207                 
00208                 $this->wSearchArea = new QWidget();
00209                 $this->vboxSearchArea = new QVBoxLayout($this->wSearchArea);
00210 
00211                 $this->vboxSearchArea->addLayout($this->hboxSearchFullView);
00212                 $this->vboxSearchArea->addWidget($this->tblSearchResults);
00213                 $this->vboxSearchArea->addLayout($this->hboxSearchPercent);
00214 
00215                 $this->splitterMain->addWidget($this->wWorkArea);
00216                 $this->splitterMain->addWidget($this->wSearchArea);
00217 
00218                 $this->vboxMain->addWidget($this->splitterMain);
00219                 $this->setLayout($this->vboxMain);
00220 
00221         }
00222 
00223         function ConnectSignals()
00224         {
00225                 // Translator button events
00226                 $this->connect($this->sldPercent, SIGNAL("valueChanged(int)"),$this->lcdPercent, SLOT("display(int)"));
00227                 $this->connect($this->btnQuit, SIGNAL("clicked()"), QApplication::instance(), SLOT("quit()"));
00228                 $this->connect($this->btnSave, SIGNAL("clicked()"), $this, SLOT("btnSave_Clicked()"));
00229                 $this->connect($this->btnSaveNext, SIGNAL("clicked()"), $this, SLOT("btnSaveNext_Clicked()"));
00230                 $this->connect($this->btnSaveNextMissing, SIGNAL("clicked()"), $this, SLOT("btnSaveNextMissing_Clicked()"));
00231                 $this->connect($this->btnNext, SIGNAL("clicked()"), $this, SLOT("btnNext_Clicked()"));
00232                 $this->connect($this->btnNextMissing, SIGNAL("clicked()"), $this, SLOT("btnNextMissing_Clicked()"));
00233 
00234                 // Search results table events
00235                 $this->connect($this->tblSearchResults, SIGNAL("cellDoubleClicked(int,int)"), $this, SLOT("tblSearchResults_DoubleClicked(int,int)"));
00236                 $this->connect($this->tblSearchResults, SIGNAL("cellClicked(int,int)"), $this, SLOT("tblSearchResults_Clicked(int,int)"));
00237         }
00238 
00239         private function FixTableColumns()
00240         {
00241                 if(!$this->TableColumnsFixed)
00242                 {
00243                         $this->TableColumnsFixed = true;
00244                         $width = $this->tblSearchResults->width();
00245                         $this->tblSearchResults->setColumnWidth(0, (int) round($width/100*10) - 10);
00246                         $this->tblSearchResults->setColumnWidth(1, (int) round($width/100*45) - 10);
00247                         $this->tblSearchResults->setColumnWidth(2, (int) round($width/100*45) - 10);
00248                 }
00249         }
00250         
00251         //function paintEvent(QPaintEvent &event)
00252         //{
00253                 //echo "hello";
00254                 //$this->painter = new QPainter($this);
00255                 //$this->painter->setBrush(Qt::blue);
00256                 //$this->painter->drawRect(new QRect(30, -5, 20, 10));
00257         //}
00258         
00259         function tblSearchResults_Clicked($y, $x)
00260         {
00261                 $item = $this->tblSearchResults->item($y, 1);
00262                 print_r($item);
00263                 if($item)
00264                 {
00265                         $this->lblSearchOriginalFull->setText($item->text());
00266                 }
00267                 $item = $this->tblSearchResults->item($y, 2);
00268                 print_r($item);
00269                 if($item)
00270                 {
00271                         $this->lblSearchTranslationFull->setText($item->text());
00272                 }
00273                 echo "Click: X:$x, Y:$y\n";
00274         }
00275         
00276         function tblSearchResults_DoubleClicked($x, $y)
00277         {
00278                 echo "DoubleClick: X:$x, Y:$y\n";
00279         }
00280         
00281         // Save and Navigate button event handlers
00282         
00283         function btnSave_Clicked()
00284         {
00285                 $this->SaveNavigate(true, LOCATE_CURR);
00286         }
00287 
00288         function btnSaveNext_Clicked()
00289         {
00290                 $this->SaveNavigate(true, LOCATE_NEXT);
00291         }
00292 
00293         function btnSaveNextMissing_Clicked()
00294         {
00295                 $this->SaveNavigate(true, LOCATE_NEXTMISSING);
00296         }
00297 
00298         function btnNext_Clicked()
00299         {
00300                 $this->SaveNavigate(false, LOCATE_NEXT);
00301         }
00302 
00303         function btnNextMissing_Clicked()
00304         {
00305                 $this->SaveNavigate(false, LOCATE_NEXTMISSING);
00306         }
00307 
00308         // Local functions for saving and searching
00309         
00310         private function SaveNavigate($save, $locType)
00311         {
00312                 $this->FixTableColumns();
00313                 
00314                 if($save)
00315                 {
00316                         echo "NOT SAVING YET";
00317                 }
00318 
00319                 $this->backend->LocateString($locType);
00320                 
00321                 $this->backend->SyncToString();
00322                 if(!empty($this->backend->LocatedString))
00323                 {
00324                         $this->txtOriginal->setText(new QString($this->backend->LocatedString->GetOriginal()));
00325                         $this->txtTranslation->setText(QString::fromUtf8($this->backend->LocatedString->GetTranslation()));
00326                         
00327                         $this->backend->ddlSearchType = 0;
00328                         $this->backend->txtFindText = $this->backend->LocatedString->GetOriginal();
00329                         $this->backend->FindStrings();
00330 
00331                         $this->ShowFindResults();
00332                         $this->ShowProjectPath();
00333                 }
00334         }
00335          
00336         private function ShowFindResults()
00337         {
00338                 if(!empty($this->backend->Translations))
00339                 {
00340                         $filterPercent = 60;
00341                         $localeID = 1;
00342         
00343                         // Count necessary rows and resize the search results table
00344                         $rows = 0;
00345                         foreach($this->backend->Translations as $id => $tr)
00346                         {
00347                                 $rows += count($tr["strings"]);
00348                         }
00349                         $this->tblSearchResults->setRowCount($rows);
00350 
00351                         $i = 0;
00352                         foreach($this->backend->Translations as $id => $tr)
00353                         {
00354                                 foreach($tr["strings"] as $key => $str)
00355                                 {
00356                                         $txt = new QString($tr["percent"]."%");
00357                                         $newItem = new QTableWidgetItem($txt);
00358                                         //$newItem->setFlags(1 | 32); //Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00359                                         $this->tblSearchResults->setItem($i, 0, $newItem);
00360 
00361                                         $txt = new QString($str->GetOriginal());
00362                                         $newItem = new QTableWidgetItem($txt);
00363                                         $this->tblSearchResults->setItem($i, 1, $newItem);
00364 
00365                                         $newItem = new QTableWidgetItem(QString::fromUtf8($str->GetTranslation(), -1));
00366                                         $this->tblSearchResults->setItem($i, 2, $newItem);
00367                                         $i++;
00368                                 }
00369                         }
00370                 }
00371         }
00372 
00373         private function ShowProjectPath()
00374         {
00375                 $path = "Project Path: ";
00376                 
00377                 // Display project path
00378                 if(!empty($this->backend->LocatedProjects))
00379                 {
00380                         //$levelIndex = 0;
00381                         for($i = count($this->backend->LocatedProjects)-1; $i >= 0; $i--)
00382                         {
00383                                 // Display project path entries
00384                                 //$this->btnLevels[$levelIndex]->setText(new QString($this->backend->LocatedProjects[$i]->GetName()));
00385                                 //$this->btnLevels[$levelIndex]->setVisible(true);
00386                                 //$levelIndex++;
00387                                 
00388                                 $path .= $this->backend->LocatedProjects[$i]->GetName();
00389                                 if($i != 0)
00390                                 {
00391                                         $path .= " -> ";
00392                                 }
00393                         }
00394 
00395                         // Hide rest of the items
00396                         //for($i = $levelIndex; $i<10; $i++)
00397                         //{
00398                         //      $this->btnLevels[$i]->setVisible(false);
00399                         //}
00400                 }
00401                 $this->lblLevels->setText(QString::fromUtf8($path));
00402         }
00403 
00404 }
00405 
00406 
00407 
00408 class MainWindowLater extends QMainWindow
00409 {
00410         public $windowCentral;
00411 
00412         public $fileMenu;
00413         public $editMenu;
00414         public $helpMenu;
00415         public $newAct;
00416         
00417         function __construct()
00418         {
00419                 parent::__construct();
00420 
00421                 $this->windowCentral = new WindowCentral();
00422                 $this->setCentralWidget($this->windowCentral);
00423                 //$statusBar = $this->statusBar();
00424                 //$this->setStatusBar($this->statusBar());
00425 
00426                 $this->CreateMenus();
00427         }
00428 
00429         function CreateMenus()
00430         {
00431                 //$menuBar = ();
00432                 $this->fileMenu = $this->menuBar()->addMenu("&File");
00433                 //$this->fileMenu->addAction(openAct);
00434                 //$this->fileMenu->addAction(saveAct);
00435                 //$this->fileMenu->addAction(saveAsAct);
00436                 //$this->fileMenu->addSeparator();
00437                 //$this->fileMenu->addAction(exitAct);
00438 
00439                 //$this->editMenu = $this->menuBar()->addMenu("&Edit");
00440                 //editMenu->addAction(cutAct);
00441                 //editMenu->addAction(copyAct);
00442                 //editMenu->addAction(pasteAct);
00443 
00444                 //$this->menuBar()->addSeparator();
00445 
00446                 //$this->helpMenu = $this->menuBar()->addMenu("&Help");
00447                 //helpMenu->addAction(aboutAct);
00448                 //helpMenu->addAction(aboutQtAct);
00449         }
00450 }
00451 
00452 
00453 ?>

Generated on Tue Mar 20 00:42:40 2007 for XarayaTranslationMemory by  doxygen 1.4.7