mainwindow.cpp 36.2 KB
Newer Older
Denis Khachko's avatar
Denis Khachko committed
1 2 3 4
#include "mainwindow.h"
#include "ui_mainwindow.h"
//#include "interface.h"

5 6 7
#include "interfaces/browserinterface.h"
#include "interfaces/browser_instanceinterface.h"

Victor Yacovlev's avatar
Victor Yacovlev committed
8

Denis Khachko's avatar
Denis Khachko committed
9 10 11 12 13 14 15 16 17 18 19 20
MainWindowTask::MainWindowTask(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindowTask)
{

cursFile="";
  course=NULL;
    curDir="";
    progChange.clear();
    connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(aboutToQuit()));

}
21
 void MainWindowTask::setup(const QDir & resourcesRoot, ExtensionSystem::SettingsPtr sett)
Denis Khachko's avatar
Denis Khachko committed
22
 {
Denis Khachko's avatar
Denis Khachko committed
23
       course=NULL;
Denis Khachko's avatar
Denis Khachko committed
24
     ui->setupUi(this);
Denis Khachko's avatar
Denis Khachko committed
25
     isReadOnly=false;
Denis Khachko's avatar
Denis Khachko committed
26 27 28
     ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
     ui->treeView->setIconSize(QSize(25,25));
     ui->treeView->setStyleSheet("icon-size: 25px;font-size: 14px;");
Denis Khachko's avatar
Denis Khachko committed
29
     settings = sett;
Denis Khachko's avatar
Denis Khachko committed
30
     customMenu.hide();
31 32
     connect(ui->loadCurs,SIGNAL(triggered()),this,SLOT(loadCourse()));
     connect(ui->actionSave,SIGNAL(triggered()),this,SLOT(saveCourse()));
Denis Khachko's avatar
Denis Khachko committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
     connect(ui->treeView,SIGNAL(clicked(QModelIndex)),this,SLOT(showText(QModelIndex)));
       connect(ui->do_task,SIGNAL(triggered()),this,SLOT(startTask()));
       qDebug()<<"Check Connect tttttttttttttttttt";
       connect(ui->checkTask,SIGNAL(triggered()),this,SLOT(checkTask()));
      connect(ui->actionReset,SIGNAL(triggered()),this,SLOT(resetTask()));
        connect(ui->actionClose,SIGNAL(triggered()),this,SLOT(Close()));
           connect(ui->actionTested,SIGNAL(triggered()),this,SLOT(returnTested()));
           connect(ui->treeView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(customContextMenuRequested(QPoint)));

           customMenu.addAction(ui->actionAdd);
           customMenu.addAction(ui->actionRemove);
           customMenu.addAction(ui->actionEdit);
       customMenu.addSeparator();
       customMenu.addAction(ui->actionup);
       customMenu.addAction(ui->actionDown);
         customMenu.addAction(ui->addDeep);
       connect(ui->actionup,SIGNAL(triggered()),this,SLOT(moveUp()));
       connect(ui->actionDown,SIGNAL(triggered()),this,SLOT(moveDown()));
           connect(ui->actionAdd,SIGNAL(triggered()),this,SLOT(addTask()));
            connect(ui->addDeep,SIGNAL(triggered()),this,SLOT(addDeepTask()));
           connect(ui->actionSaveK,SIGNAL(triggered()),this,SLOT(saveKurs()));
            connect(ui->actionSaveKas,SIGNAL(triggered()),this,SLOT(saveKursAs()));
           connect(ui->actionRemove,SIGNAL(triggered()),this,SLOT(deleteTask()));
56
     connect(ui->actionNext,SIGNAL(triggered()),this,SLOT(nextTask()));
Denis Khachko's avatar
Denis Khachko committed
57 58 59 60
         //  newDialog=new newKursDialog();
          // connect(ui->actionNewK,SIGNAL(triggered()),this,SLOT(newKurs()));
         //  editDialog = new EditDialog(this);
          // connect(ui->actionEdit,SIGNAL(triggered()),this,SLOT(editTask()));
Denis Khachko's avatar
Denis Khachko committed
61 62 63 64 65 66
          // ui->menuKurs->menuAction()->setEnabled(false);
           setEditTaskEnabled(false);
           ui->treeView->setSelectionMode(QAbstractItemView::SingleSelection);
           editRoot=new QLineEdit(ui->treeView);
           editRoot->hide();
           connect(editRoot,SIGNAL(editingFinished ()),this,SLOT(endRootEdit()));
Denis Khachko's avatar
Denis Khachko committed
67
           ui->treeView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Denis Khachko's avatar
Denis Khachko committed
68 69 70
isTeacher=false;
       onTask=false;
       cursFile="";
71
       setWindowIcon(QIcon(resourcesRoot.absoluteFilePath("10.png")));
72
        setupWebView();
Denis Khachko's avatar
Denis Khachko committed
73 74
       //ui->textBrowser->setVisible(false);
 };
75 76 77 78 79 80 81 82 83
void MainWindowTask::nextTask()
{
    if(ui->treeView->indexBelow(curTaskIdx).isValid())
    {
        ui->treeView->setCurrentIndex(ui->treeView->indexBelow(curTaskIdx));
       // curTaskIdx=ui->treeView->currentIndex();
        showText(ui->treeView->currentIndex());
    } 
}
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133

void MainWindowTask::setupWebView()
{
    using namespace ExtensionSystem;
    using namespace Shared;

    BrowserInterface * browserPlugin
            = PluginManager::instance()->findPlugin<BrowserInterface>();

    QWidget * webViewComponent = 0;
    simpleBrowserWidget_ = 0;
    browserPluginInstance_ = 0;

    if (browserPlugin) {
        browserPluginInstance_ = browserPlugin->createBrowser();
        webViewComponent = browserPluginInstance_->widget();
    }
    else {
        simpleBrowserWidget_ = new QTextBrowser();
        webViewComponent = simpleBrowserWidget_;
    }

    webViewComponent->setParent(ui->webView);
    webViewComponent->setMinimumWidth(200);
    QVBoxLayout * l = new QVBoxLayout;
    l->setContentsMargins(0, 0, 0, 0);
    ui->webView->setLayout(l);
    l->addWidget(webViewComponent);
}

void MainWindowTask::setTaskViewHtml(const QString &data)
{
    if (simpleBrowserWidget_) {
        simpleBrowserWidget_->setHtml(data);
    }
    else if (browserPluginInstance_) {
        browserPluginInstance_->setContent(data);
    }
}

void MainWindowTask::setTaskViewUrl(const QUrl &url)
{
    if (simpleBrowserWidget_) {
        simpleBrowserWidget_->setSource(url);
    }
    else if (browserPluginInstance_) {
        browserPluginInstance_->go(url);
    }
}

Denis Khachko's avatar
Lost 2  
Denis Khachko committed
134
QList<QAction*> MainWindowTask::getActions()
Denis Khachko's avatar
Denis Khachko committed
135 136 137 138
{
    QList<QAction*> toRet;
    toRet.append(ui->loadCurs);
    toRet.append(ui->checkTask);
Denis Khachko's avatar
Denis Khachko committed
139 140 141
    toRet.append(ui->actionSave);
    toRet.append(ui->actionReset);
    toRet.append(ui->actionTested);
Denis Khachko's avatar
Lost 2  
Denis Khachko committed
142
    return toRet;
Denis Khachko's avatar
Denis Khachko committed
143
}
Denis Khachko's avatar
Denis Khachko committed
144

Denis Khachko's avatar
Denis Khachko committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
MainWindowTask::~MainWindowTask()
{
    delete ui;
}

void MainWindowTask::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}
Denis Khachko's avatar
Denis Khachko committed
161 162
void MainWindowTask::updateLastFiles(const QString newFile )
{
Denis Khachko's avatar
Denis Khachko committed
163
      QStringList lastFiles= settings->value("Courses/LastFiles","").toString().split(";");
Denis Khachko's avatar
Denis Khachko committed
164
    qDebug()<<lastFiles;
Denis Khachko's avatar
Denis Khachko committed
165
     qDebug()<<settings->locationDirectory();
Denis Khachko's avatar
Denis Khachko committed
166 167 168 169 170 171 172
    if(lastFiles.indexOf(newFile)<0)lastFiles.prepend(newFile);
    int max_fid=std::min(lastFiles.count(),10);
    QString sett="";
    for(int i=0;i<max_fid;i++)
    {
        sett+= lastFiles.at(i)+";";
    }
Denis Khachko's avatar
Denis Khachko committed
173 174
    settings->setValue("Courses/LastFiles",sett);
    interface->rebuildRescentMenu();
Denis Khachko's avatar
Denis Khachko committed
175
};
Denis Khachko's avatar
Denis Khachko committed
176 177 178 179 180 181 182 183 184
void MainWindowTask::loadCourseData(const QString fileName)
{

course=new courseModel();
connect(course,SIGNAL(dataChanged (QModelIndex ,QModelIndex )),ui->treeView,SLOT(dataChanged(QModelIndex,QModelIndex)));
int tasks=course->loadCourse(fileName);
course->setTeacher(isTeacher);
if(tasks==-1)
{
Denis Khachko's avatar
Denis Khachko committed
185
QMessageBox::information( 0, "", trUtf8("Ошибка открытия файла: ") + fileName, 0,0,0);
Denis Khachko's avatar
Denis Khachko committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199
return;
};
ui->treeView->setModel(course);
curTaskIdx=QModelIndex();
onTask=false;
ui->actionSave->setEnabled(true);

changes.cleanChanges();
cursFile=fileName;
};
void MainWindowTask::loadMarks(const QString fileName)
{
    QDomDocument workXml;
    QFile f(fileName);
Denis Khachko's avatar
Denis Khachko committed
200
    
Denis Khachko's avatar
Denis Khachko committed
201 202 203 204 205 206
    if  (!f.open(QIODevice::ReadOnly))
    {
        QMessageBox::information( 0, "", trUtf8("Ошибка открытия файла: ") + fileName, 0,0,0);
        return;

    };
Denis Khachko's avatar
Denis Khachko committed
207 208 209 210 211 212 213
    QFileInfo fi(f);
    if(!fi.isWritable())
    {
       QMessageBox::information( 0, "", trUtf8("Файл загружен только для чтения, изменение не будут сохранены: ") + fileName, 0,0,0);
        isReadOnly=true;
    }else
     isReadOnly=false;   
Denis Khachko's avatar
Denis Khachko committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
if(f.atEnd())
    {
    QMessageBox::information( 0, "", trUtf8("Ошибка открытия файла ,файл пуст: ") + fileName, 0,0,0);
    return;
    };
cursWorkFile.setFileName(f.fileName());
QString error;
int str,pos;
workXml.setContent(f.readAll(),true,&error,&str,&pos);
qDebug()<<"File parce:"<<error<<"str"<<str<<" pos"<<pos;

QDomElement root=workXml.documentElement ();
if(root.tagName()!="COURSE")
  {
        QMessageBox::information( 0, "", trUtf8("Ошибка загрузки файла: ") + fileName, 0,0,0);
        return;
  };
QDomElement fileEl=root.firstChildElement("FILE");
QString krsFile=fileEl.attribute("fileName");
loadCourseData(krsFile);//Gruzim kurs

if(cursFile!=krsFile){//Esli ne udalos po puti - ishem v toyje direktorii
    QFileInfo finf(fileEl.attribute("fileName"));
    QFileInfo cfi(cursWorkFile);
    qDebug()<<"PATH"<<cfi.dir().canonicalPath()+"/"+finf.fileName();
    krsFile=cfi.dir().canonicalPath()+"/"+finf.fileName();
    curDir=cfi.dir().canonicalPath();
Denis Khachko's avatar
Denis Khachko committed
241 242
    QFileInfo krsFi(krsFile);
    if(krsFi.isReadable())
Denis Khachko's avatar
Denis Khachko committed
243 244 245 246 247
    loadCourseData(krsFile);

}

QString fileN=fileEl.attribute("fileName");
Denis Khachko's avatar
Denis Khachko committed
248
//qDebug()<<"KURS ZAGRUZILI";
Denis Khachko's avatar
Denis Khachko committed
249
if(cursFile!=krsFile){
Denis Khachko's avatar
Denis Khachko committed
250
    QMessageBox::information( 0, "", trUtf8("Не найден файл курса:") + fileEl.attribute("fileName"), 0,0,0);
Denis Khachko's avatar
Denis Khachko committed
251 252 253 254 255 256 257
    fileN=getFileName(krsFile);
    loadCourseData(fileN);
    if(cursFile!=fileN)return;
    }
QFileInfo fi_kurs=QFileInfo(krsFile);
curDir=fi_kurs.absolutePath();
QDomNodeList marksElList=root.elementsByTagName("MARK"); //Оценки
Denis Khachko's avatar
Denis Khachko committed
258
//qDebug()<<"Loading marks "<<marksElList.count();
Denis Khachko's avatar
Denis Khachko committed
259 260 261 262 263 264 265 266 267
for(int i=0;i<marksElList.count();i++)
 {
 int taskId=marksElList.at(i).toElement().attribute("testId").toInt();
 int mark=marksElList.at(i).toElement().attribute("mark").toInt();
 qDebug()<<"task:"<<taskId<<" mark:"<<mark;
 course->setMark(taskId,mark);
 changes.setMark(taskId,mark);
 };

Denis Khachko's avatar
Denis Khachko committed
268
//qDebug()<<"Loading user prgs...";
Denis Khachko's avatar
Denis Khachko committed
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
QDomNodeList prgElList=root.elementsByTagName("USER_PRG");//Программы
for(int i=0;i<prgElList.count();i++)
 {
 int taskId=prgElList.at(i).toElement().attribute("testId").toInt();
 qDebug()<<"Tassk id"<<taskId;
 QString prg =prgElList.at(i).toElement().attribute("prg");
 QModelIndex tIdx=course->getIndexById(taskId);

 if(progChange.indexOf(taskId)==-1){

     progChange.append(taskId);
      };
 course->setUserText(taskId,prg);

 };

QDomNodeList prgElListT=root.elementsByTagName("TESTED_PRG");//Программы тестированные
for(int i=0;i<prgElListT.count();i++)
 {
 int taskId=prgElListT.at(i).toElement().attribute("testId").toInt();
 QString prg =prgElListT.at(i).toElement().attribute("prg");

 course->setUserTestedText(taskId,prg);

 };
};
Denis Khachko's avatar
Denis Khachko committed
295 296 297 298 299 300 301
 void MainWindowTask::loadCourseFromFile(const QString & file)
{QFileInfo fi(file);
    if(!fi.exists())
    {
        
        return;
    };
Denis Khachko's avatar
Denis Khachko committed
302

Denis Khachko's avatar
Denis Khachko committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
    baseKursFile=fi;
    curDir=fi.absolutePath ();
    settings->setValue("Directories/Kurs", curDir);
    qDebug()<<"curDir"<<curDir;
    QString fileName=file;
    progChange.clear();
    if(fileName.right(9)==".work.xml")//Загрузка оценок и программ
    {
        loadMarks(fileName);
        this->show();
        return;
    }else
        cursWorkFile.setFileName("");
    loadCourseData(fileName);
    QString cText=course->courceDescr();
    
    
    if(cText.right(4)==".htm" ||cText.right(5)==".html" )
    {
        loadHtml(cText);
323
    }else setTaskViewHtml(cText);
Denis Khachko's avatar
Denis Khachko committed
324 325 326 327
    // if(isTeacher)ui->actionEdit->setEnabled(true);
    setWindowTitle(course->name()+trUtf8(" - Практикум"));
    updateLastFiles(fileName);
    interface->lockContrls();
328
    interface->setPreProgram(QVariant(""));
Denis Khachko's avatar
Denis Khachko committed
329 330 331
    ui->checkTask->setEnabled(false);
    this->show();
};
Denis Khachko's avatar
Denis Khachko committed
332 333 334 335 336 337

void MainWindowTask::loadCourse()
{
    editRoot->hide();
    ui->splitter->setEnabled(true);
    QString dir=settings->value("Directories/Kurs","").toString();
Denis Khachko's avatar
Denis Khachko committed
338
    qDebug()<<"Dir "<<dir;
Denis Khachko's avatar
Denis Khachko committed
339
    QDir chD(dir);
Denis Khachko's avatar
Denis Khachko committed
340 341
    QDir resDir=interface->myResourcesDir();
    resDir.cdUp();
Denis Khachko's avatar
Denis Khachko committed
342
    resDir.cd("courses");
343 344 345
    if(0 == dir.length() || !chD.exists()) {
        dir=resDir.canonicalPath();
    }
Denis Khachko's avatar
Denis Khachko committed
346 347 348 349 350
//    QFileDialog dialog(this,trUtf8("Открыть файл"),dir, "(*.kurs.xml *.work.xml)");
//     dialog.setAcceptMode(QFileDialog::AcceptOpen);
//     if(!dialog.exec())return;


Denis Khachko's avatar
Denis Khachko committed
351
     QString	File=QFileDialog::getOpenFileName(this, QString::fromUtf8 ("Открыть файл"), dir, "Xml (*.xml)");
Denis Khachko's avatar
Denis Khachko committed
352
     QFileInfo fi(File);
Denis Khachko's avatar
Denis Khachko committed
353 354 355 356 357
    if(!fi.exists())
    {
           
        return;
    };
Denis Khachko's avatar
Denis Khachko committed
358
    this->showNormal();
Denis Khachko's avatar
Denis Khachko committed
359 360 361 362 363 364 365 366 367

     baseKursFile=fi;
     curDir=fi.absolutePath ();
     settings->setValue("Directories/Kurs", curDir);
     qDebug()<<"curDir"<<curDir;
     QString fileName=File;
     progChange.clear();
     if(fileName.right(9)==".work.xml")//Загрузка оценок и программ
     {
Denis Khachko's avatar
Denis Khachko committed
368
         isReadOnly=false;
Denis Khachko's avatar
Denis Khachko committed
369
         loadMarks(fileName);
370 371
         Q_EMIT activateRequest();
//         this->show();
Denis Khachko's avatar
Denis Khachko committed
372
         return;
373 374
     }
    bool createDefaultWorkFile=true;
Victor Yacovlev's avatar
Victor Yacovlev committed
375 376 377 378 379 380 381 382 383 384 385 386
    QMessageBox msgBoxCreateWorkbook(
                QMessageBox::Question,
                trUtf8("Практикум"),
                trUtf8("Вы хотите создать тетрадь?"),
                QMessageBox::Yes | QMessageBox::No,
                this
                );
    msgBoxCreateWorkbook.button(QMessageBox::Yes)->setText(trUtf8("Создать"));
    msgBoxCreateWorkbook.button(QMessageBox::No)->setText(trUtf8("Не создавать"));
    int ans = msgBoxCreateWorkbook.exec();
//            ans = QMessageBox::question(this, trUtf8("Практикум"), trUtf8("Вы хотите создать тетрадь?"),
//                    QMessageBox::Yes | QMessageBox::No , QMessageBox::Yes);
387 388 389 390 391
            if (ans == QMessageBox::Yes)
            {
                createDefaultWorkFile=false;
                
            };
Denis Khachko's avatar
Denis Khachko committed
392
    
Denis Khachko's avatar
Denis Khachko committed
393 394
     cursWorkFile.setFileName("");
     loadCourseData(fileName);
Denis Khachko's avatar
Denis Khachko committed
395
     isReadOnly=false;
396
     interface->setPreProgram(QVariant(""));
Denis Khachko's avatar
Denis Khachko committed
397
     QString cText=course->courceDescr();
Denis Khachko's avatar
Denis Khachko committed
398
  
Denis Khachko's avatar
Denis Khachko committed
399 400 401 402

  if(cText.right(4)==".htm" ||cText.right(5)==".html" )
  {
      loadHtml(cText);
403
  }else setTaskViewHtml(cText);
Denis Khachko's avatar
Denis Khachko committed
404
 // if(isTeacher)ui->actionEdit->setEnabled(true);
Denis Khachko's avatar
Denis Khachko committed
405
  setWindowTitle(course->name()+trUtf8(" - Практикум"));
Denis Khachko's avatar
Denis Khachko committed
406
    updateLastFiles(fileName);
407 408
    interface->lockContrls();
    ui->checkTask->setEnabled(false);
409 410
    Q_EMIT activateRequest();
//    this->show();
411 412 413 414 415 416
    if(createDefaultWorkFile)
    {
        markProgChange();
        //curDir=QDir::currentPath();
        qDebug()<<curDir;

417
        cursWorkFile.setFileName(QDir::tempPath()+"/default.work.xml");
Denis Khachko's avatar
Denis Khachko committed
418
        
419 420 421 422 423
        saveCourseFile();
    }else
    {
        saveCourse();
    };
Denis Khachko's avatar
Denis Khachko committed
424
    
Denis Khachko's avatar
Denis Khachko committed
425 426
};

Denis Khachko's avatar
Denis Khachko committed
427 428 429
void MainWindowTask::openRescent()
{
    
Denis Khachko's avatar
Denis Khachko committed
430

Denis Khachko's avatar
Denis Khachko committed
431 432
    
    QAction *s = qobject_cast<QAction*>(sender());
Denis Khachko's avatar
Denis Khachko committed
433 434
    
    loadCourseFromFile(s->property ( "fullName" ).toString());
Denis Khachko's avatar
Denis Khachko committed
435
  //  if( LoadFromFile(RobotFile)!=0)QMessageBox::information( mainWidget(), "", QString::fromUtf8("Ошибка открытия файла! ")+RobotFile, 0,0,0);
Denis Khachko's avatar
Denis Khachko committed
436
Q_EMIT activateRequest();
Denis Khachko's avatar
Denis Khachko committed
437
};
Denis Khachko's avatar
Denis Khachko committed
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513

void MainWindowTask::setUpDown(QModelIndex index)
{
    if(!isTeacher){ui->actionup->setEnabled(false);
        ui->actionDown->setEnabled(false);
    }
    return;
    if(course->hasUpSib(index))ui->actionup->setEnabled(true);
      else ui->actionup->setEnabled(false);
      if(course->hasDownSib(index))ui->actionDown->setEnabled(true);
        else ui->actionDown->setEnabled(false);
};


void MainWindowTask::moveUp()

{
    curTaskIdx=course->moveUp(curTaskIdx);
    QModelIndex par=curTaskIdx.parent();
    ui->treeView->setCurrentIndex(curTaskIdx);
    setUpDown(curTaskIdx);


   ui->treeView->collapse(par);
   ui->treeView->expand(par);
saveBaseKurs();
};
void MainWindowTask:: moveDown()
{ ui->treeView->setCurrentIndex(curTaskIdx);

    curTaskIdx=course->moveDown(curTaskIdx);
    ui->treeView->setCurrentIndex(curTaskIdx);
    setUpDown(curTaskIdx);
  //ui->treeView->dataChanged(curTaskIdx,ui->treeView->indexAbove(curTaskIdx));
   //showText(curTaskIdx);
   // ui->treeView->update(curTaskIdx);

   ui->treeView->collapse(curTaskIdx.parent());
   ui->treeView->expand(curTaskIdx.parent());
};


void MainWindowTask::showText(const QModelIndex & index )
 {
      editRoot->hide();
    qDebug()<<"TASK IDX:"<<curTaskIdx.internalId();
    if(index.internalId()>0)setEditTaskEnabled(true);
    else setEditTaskEnabled(false);
    setUpDown(index);
    if(index==curTaskIdx)return;
//    if(onTask)
//    {
//        QMessageBox::StandardButton ans;
//        ans = QMessageBox::question(this, trUtf8("Задание"), trUtf8("Вы хотите сменить задание?"),
//                                                                                                                        QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes);
//        if ((ans == QMessageBox::Cancel)||(ans == QMessageBox::No))
//        {
//            qDebug()<<"Cancel";
//        if(curTaskIdx.internalId()>0)ui->treeView->setCurrentIndex(curTaskIdx);
//            return;};

//    }
    if(curTaskIdx.internalId()>0)
    {
        markProgChange();
    }
    onTask=false;
    ui->checkTask->setEnabled(false);
    QString taskText=course->getTaskText(index);
 //ui->textBrowser->setText(taskText);



 if(taskText.right(4)==".htm" ||taskText.right(5)==".html" )
 {
     loadHtml(taskText);
514
 }else setTaskViewHtml(taskText);
Denis Khachko's avatar
Denis Khachko committed
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
  qDebug()<<"TaskText:"<<course->getTaskText(index);
 curTaskIdx=index;

 if(course->isTask(curTaskIdx.internalId()) && curTaskIdx.internalId()>0 && course->taskAvailable(curTaskIdx.internalId()))
   {
     ui->do_task->setEnabled(true);
     startTask();
     ui->do_task->setEnabled(false);
      ui->actionReset->setEnabled(true);
      QString testedText=course->getUserTestedText(curTaskIdx.internalId());
      qDebug()<<"TESTED TEXT"<<testedText;
      if(testedText!="")ui->actionTested->setEnabled(true);
   }
 else {
           ui->do_task->setEnabled(false);
           ui->actionReset->setEnabled(false);
           ui->actionTested->setEnabled(false);
       };
 };

void MainWindowTask::loadHtml(QString fileName)
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
{    
    const QString absolutePath = QDir(curDir).absoluteFilePath(fileName);
    const QUrl url = QUrl::fromLocalFile(absolutePath);
    setTaskViewUrl(url);
//    qDebug()<<"LoadHtml"<<fileName;
//    if(fileName.isEmpty())return;
//    QFile inp(curDir+'/'+fileName);
//    if  (!inp.open(QIODevice::ReadOnly))
//    {
//    QMessageBox::information( 0, "", trUtf8("Ошибка чтения: ") + fileName, 0,0,0);
//    return;
//    };
//    QString htmlData=QString::fromUtf8(inp.readAll());
//    //ui->textBrowser->setHtml(htmlData);

//    ui->webView->setHtml(htmlData,QUrl("file://"+curDir+'/'+fileName));
//    inp.close();
Denis Khachko's avatar
Denis Khachko committed
553 554 555 556 557 558 559 560 561 562

};
void MainWindowTask::startTask()
 {editRoot->hide();
    qDebug()<<"StartTask";
     if(curTaskIdx.internalId()<=0)
     {
         QMessageBox::about(NULL, trUtf8("Не выбрано задание"),trUtf8("Необходимо выбрать задание"));
         return;
     }
563
     if(course->csName(curTaskIdx.internalId()).toLower()!=CS)
Denis Khachko's avatar
Denis Khachko committed
564 565 566 567 568 569
     {
         QMessageBox::about(NULL, trUtf8("Неправильное окружение"),trUtf8("Необходим ")+course->csName(curTaskIdx.internalId()));
         return;
     }

     QString progFile=course->progFile(curTaskIdx.internalId());
Denis Khachko's avatar
Denis Khachko committed
570
//interface->setTesting(loadTestAlg(course->getTaskCheck(curTaskIdx)));
Denis Khachko's avatar
Denis Khachko committed
571 572 573 574 575 576 577 578
QFileInfo ioDir(curDir+"/"+course->progFile(curTaskIdx.internalId()));
qDebug()<<"PRG FILE"<<course->progFile(curTaskIdx.internalId());
if(ioDir.isFile())
     {
     interface->setParam("input dir",ioDir.absoluteFilePath());
     };
     task.isps=course->Modules(curTaskIdx.internalId());
     task.name=course->getTitle(curTaskIdx.internalId());
Denis Khachko's avatar
Denis Khachko committed
579
       qDebug()<<"ISPS"<<task.isps<<"task.name"<<task.name;
580
       task.fields.clear();
Denis Khachko's avatar
Denis Khachko committed
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
       for(int i=0;i<task.isps.count();i++)
       {
      // task.Scripts.append(loadScript(course->Script(curTaskIdx.internalId(),task.isps[i])));
       QStringList t_fields=course->Fields(curTaskIdx.internalId(),task.isps[i]);
       qDebug()<<"fields"<<t_fields;
       task.fields.clear();
        for(int j=0;j<t_fields.count();j++)
            {
                qDebug()<<"Cur Dir"<<curDir;
            task.fields.insertMulti(task.isps[i],curDir+'/'+t_fields[j]);
            qDebug()<<curDir+'/'+t_fields[j];

            };
        qDebug()<<"Fields!!!!"<<task.fields;
        }
       qDebug()<<"MODULES:"<<course->Modules(curTaskIdx.internalId());
Denis Khachko's avatar
Denis Khachko committed
597
  if(!interface->startNewTask(course->Modules(curTaskIdx.internalId()),&task))QMessageBox::about(NULL, trUtf8("Невозможно выполнить задание"),trUtf8("Нет необходимых исполнителей"));
Denis Khachko's avatar
Denis Khachko committed
598 599 600 601 602 603 604 605 606 607 608 609 610 611
  if(course->getUserText(curTaskIdx.internalId())!="")
  {
      interface->setPreProgram(QVariant(course->getUserText(curTaskIdx.internalId())));
      ui->actionReset->setEnabled(true);
  }
   else
      if(!progFile.isEmpty())interface->setPreProgram(QVariant(curDir+'/'+progFile));



//qDebug()<<"Scripts "<<task.Scripts;
 ui->do_task->setEnabled(false);
 ui->checkTask->setEnabled(true);
 onTask=true;
612 613 614 615 616 617
     
     QModelIndex nextT=ui->treeView->indexBelow(curTaskIdx);
 if(nextT.isValid() && course->isTask(nextT.internalId()) && nextT.internalId()>0 && course->taskAvailable(nextT.internalId()))
     ui->actionNext->setEnabled(true);
     else
      ui->actionNext->setEnabled(false);
Denis Khachko's avatar
Denis Khachko committed
618 619 620 621
 //ui->loadCurs->setEnabled(false);
 qDebug()<<"end load task";
 if(progChange.indexOf(curTaskIdx.internalId())==-1)progChange.append(curTaskIdx.internalId());
 };
622 623 624 625 626 627





void MainWindowTask::checkTask()
Denis Khachko's avatar
Denis Khachko committed
628 629 630 631 632 633 634 635 636 637 638 639
 {
     qDebug()<<"CheckTASK";
     if(!onTask){qDebug()<<"!onTASK";return;};


markProgChange();
if(!cursWorkFile.exists()){

    QMessageBox::information( 0, "", trUtf8("Нужно завести файл рабочей тетради "), 0,0,0);
    saveCourse();
      };
course->setMark(curTaskIdx.internalId(),0);
Denis Khachko's avatar
Denis Khachko committed
640

Denis Khachko's avatar
Denis Khachko committed
641 642
     qDebug()<<"task"<<task.isps;
interface->startProgram(QVariant("TODO LOAD SCRIPT"),&task);
Denis Khachko's avatar
Denis Khachko committed
643 644 645 646
   //ui->loadCurs->setEnabled(false);

 };

Denis Khachko's avatar
Denis Khachko committed
647 648 649 650
 void MainWindowTask::lockControls()
{
    ui->splitter->setEnabled(false);
    ui->checkTask->setEnabled(false);
651
    ui->loadCurs->setEnabled(false);
652
    ui->actionNext->setEnabled(false);
Denis Khachko's avatar
Denis Khachko committed
653
};
Denis Khachko's avatar
Denis Khachko committed
654

Denis Khachko's avatar
Denis Khachko committed
655 656 657 658
void MainWindowTask::unlockControls()
{
    ui->splitter->setEnabled(true);
    ui->checkTask->setEnabled(true);
659 660 661 662 663 664 665 666
    ui->loadCurs->setEnabled(true);
    
    QModelIndex nextT=ui->treeView->indexBelow(curTaskIdx);
    if(nextT.isValid() && course->isTask(nextT.internalId()) && nextT.internalId()>0 && course->taskAvailable(nextT.internalId()))
    ui->actionNext->setEnabled(true);
    else
        ui->actionNext->setEnabled(false);

Denis Khachko's avatar
Denis Khachko committed
667
};
Denis Khachko's avatar
Denis Khachko committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706

void  MainWindowTask::setMark(int mark)
{
    ui->loadCurs->setEnabled(true);
    if(!onTask)return;
    ui->loadCurs->setEnabled(true);
  qDebug()<<"ui->cource enabled!";
    ui->splitter->setEnabled(true);
    ui->actionTested->setEnabled(true);
    qDebug()<<"ui->treeView enabled!";
    ui->checkTask->setEnabled(true);
    if((course->taskMark(curTaskIdx.internalId())<mark) &&  (course->taskMark(curTaskIdx.internalId())>0))return;

    course->setUserTestedText(curTaskIdx.internalId(),interface->getText());
    qDebug()<<"Mark:"<<mark;
    course->setMark(curTaskIdx.internalId(),mark);
    changes.setMark(curTaskIdx.internalId(),mark);
    ui->treeView->dataChanged(curTaskIdx,curTaskIdx);
    //if(mark==10)onTask=false;else onTask=true;

};
QString MainWindowTask::loadScript(QString file_name)
{
    qDebug()<<"Script file name:"<<file_name;
    if(file_name.isEmpty())return "";
    QFile file(curDir+"/"+file_name);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        QMessageBox::about(NULL, trUtf8("Ошибка"),trUtf8("Невозможно открыть ")+curDir+"/"+file_name);
        return "";
    };
    return file.readAll();
};


void MainWindowTask::saveCourse()
{
    editRoot->hide();
   markProgChange();
Victor Yacovlev's avatar
Victor Yacovlev committed
707 708 709 710 711 712 713 714
//    QFileDialog dialog(this,trUtf8("Сохранить изменения"),curDir+"/", "Work files(*.work.xml);;All files (*)");
//    dialog.setDefaultSuffix("work.xml");
//    dialog.setAcceptMode(QFileDialog::AcceptSave);
//    if(!dialog.exec())return;
//    QFileInfo fi(dialog.selectedFiles().first());
//    //curDir=fi.absolutePath ();
//    qDebug()<<"curDir"<<curDir;
//    QString fileName=dialog.selectedFiles().first();
715 716 717 718 719
    QString open=curDir;
    QFileInfo fi=QFileInfo(curDir);
    if(!fi.isWritable())open=QDir::currentPath();
    
    
Denis Khachko's avatar
Denis Khachko committed
720
  QString fileName = QFileDialog::getSaveFileName(
Victor Yacovlev's avatar
Victor Yacovlev committed
721 722
               this,
               trUtf8("Сохранить изменения"),
723
               open,
724
               trUtf8("Тетради(*.work.xml);;Все файлы (*)")
Victor Yacovlev's avatar
Victor Yacovlev committed
725
               );
Denis Khachko's avatar
Denis Khachko committed
726 727
    QString type=fileName.right(9);
    if(type!=".work.xml")fileName+=".work.xml";
Denis Khachko's avatar
Denis Khachko committed
728
    cursWorkFile.setFileName(fileName);
Denis Khachko's avatar
Denis Khachko committed
729
    updateLastFiles(fileName);
Denis Khachko's avatar
Denis Khachko committed
730 731 732 733 734
    saveCourseFile();

};
void MainWindowTask::saveCourseFile()
{
Denis Khachko's avatar
Denis Khachko committed
735
    if(isReadOnly)return;
Denis Khachko's avatar
Denis Khachko committed
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851
    qDebug()<<"Save cource file";
    QDomDocument saveXml;

    QDomElement	crsEl=saveXml.createElement("COURSE");
    QDomElement	fileEl=saveXml.createElement("FILE");
    QDomAttr crsAtt=saveXml.createAttribute("fileName");
    crsAtt.setValue(cursFile);
    fileEl.setAttributeNode(crsAtt);

    crsEl.appendChild(fileEl);
    saveXml.appendChild(crsEl);
    QDomElement	mrksEl=saveXml.createElement("MARKS");

    //USER PROGRAMS n TESTED PROGRAMS
    for(int i=0;i<progChange.count();i++){
    QDomElement	prgEl=saveXml.createElement("USER_PRG");
    QDomAttr testIdprg=saveXml.createAttribute("testId");
    testIdprg.setValue(QString::number(progChange[i]));
    QDomAttr userPrg=saveXml.createAttribute("prg");
    userPrg.setValue(course->getUserText(progChange[i]));
    prgEl.setAttributeNode(testIdprg);
    prgEl.setAttributeNode(userPrg);
    crsEl.appendChild(prgEl);

    QDomElement	prgElT=saveXml.createElement("TESTED_PRG");
    QDomAttr testIdprgT=saveXml.createAttribute("testId");
    testIdprgT.setValue(QString::number(progChange[i]));
    QDomAttr userPrgT=saveXml.createAttribute("prg");
    userPrgT.setValue(course->getUserTestedText(progChange[i]));
    prgElT.setAttributeNode(testIdprg);
    prgElT.setAttributeNode(userPrgT);
    crsEl.appendChild(prgElT);



     }
    //END USER PROGRAMS




    QMapIterator<int, int> i(changes.marksChanged);
    while (i.hasNext()) {
        i.next();
        QDomElement mrk=saveXml.createElement("MARK");
        QDomAttr testId=saveXml.createAttribute("testId");
        testId.setValue(QString::number(i.key()));
        QDomAttr mvalue=saveXml.createAttribute("mark");
        mvalue.setValue(QString::number(i.value()));
        mrk.setAttributeNode(testId);
        mrk.setAttributeNode(mvalue);
        mrksEl.appendChild(mrk);
    }
    crsEl.appendChild(mrksEl);





          if  (!cursWorkFile.open(QIODevice::WriteOnly))
          {
          QMessageBox::information( 0, "", trUtf8("Ошибка записи: ") + cursWorkFile.fileName(), 0,0,0);
          return;
          };
    cursWorkFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    cursWorkFile.write(saveXml.toByteArray());
    cursWorkFile.close();

};

void MainWindowTask::markProgChange()
{

    course->setUserText(curTaskIdx,interface->getText());
    if(progChange.indexOf(curTaskIdx.internalId())==-1)progChange.append(curTaskIdx.internalId());
    if(!cursWorkFile.exists())
    {
      qDebug()<<"!cursWorkFile";
    }else saveCourseFile();

}
QString MainWindowTask::getFileName(QString fileName)
{
    QFileInfo finf(fileName);
    qDebug()<<"GET FILE!";
//    QFileDialog dialog(this,trUtf8("Открыть файл"),curDir, finf.fileName()+" *.kurs.xml");
//    dialog.setAcceptMode(QFileDialog::AcceptOpen);
//    if(!dialog.exec())return "";
//    QFileInfo fi(dialog.selectedFiles().first());



    QString	File=QFileDialog::getOpenFileName(this, QString::fromUtf8 ("Открыть файл"), curDir,  finf.fileName()+" *.kurs.xml");
    QFileInfo fi(File);


    return File;
};

void MainWindowTask::resetTask()
{
    QString progFile=course->progFile(curTaskIdx.internalId());


     if(!progFile.isEmpty())interface->setPreProgram(QVariant(curDir+'/'+progFile));
    course->setUserText(curTaskIdx,"");


};
void MainWindowTask::Close()
{
    qDebug()<<cursFile;
    if(cursFile!="")markProgChange();
    saveBaseKurs();
    close();
};
Denis Khachko's avatar
Denis Khachko committed
852 853
void MainWindowTask::showEvent(QShowEvent * event)
{
854
    ui->splitter->restoreState(settings->value("Window/SpliterState")
Denis Khachko's avatar
Denis Khachko committed
855
                 .toByteArray());
856
    QByteArray settlist=settings->value("Window/SpliterPos").toByteArray();
Denis Khachko's avatar
Denis Khachko committed
857 858 859 860
    qDebug()<<settlist;
    ui->splitter->restoreGeometry(settlist);
};

861 862 863 864 865 866 867
void MainWindowTask::hideEvent(QHideEvent * event)
{
    settings->setValue("Window/SpliterPos",ui->splitter->saveGeometry());
    settings->setValue("Window/SpliterState",ui->splitter->saveState());
    settings->flush();
};

Denis Khachko's avatar
Denis Khachko committed
868 869
void MainWindowTask::closeEvent(QCloseEvent *event)
{
Denis Khachko's avatar
Denis Khachko committed
870 871 872
    
   
    
873 874 875
    settings->setValue("Window/SpliterPos",ui->splitter->saveGeometry());
    settings->setValue("Window/SpliterState",ui->splitter->saveState());
    settings->flush();
Denis Khachko's avatar
Denis Khachko committed
876 877
    qDebug()<<ui->splitter->saveGeometry();
    qDebug()<<"CLOSE TASK WINDOW";
Denis Khachko's avatar
Denis Khachko committed
878 879
  if(!course)return;
  qDebug()<<"START CLOSE TASK WINDOW";
Denis Khachko's avatar
Denis Khachko committed
880
 
Denis Khachko's avatar
Denis Khachko committed
881 882
        markProgChange();
        qDebug()<<"CLOSE TASK WINDOW";
Denis Khachko's avatar
Denis Khachko committed
883
        event->accept();
Denis Khachko's avatar
Denis Khachko committed
884 885 886
        close();

};
Denis Khachko's avatar
Denis Khachko committed
887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921
bool MainWindowTask::safeToQuit()
{
    if(!course)return true;
    if(!cursWorkFile.exists())
    {
        QMessageBox msgBoxCreateWorkbook(
                                         QMessageBox::Question,
                                         trUtf8("Практикум"),
                                         trUtf8("Вы хотите сохранить работу?"),
                                         QMessageBox::Yes | QMessageBox::No|QMessageBox::Cancel,
                                         this
                                         );
        msgBoxCreateWorkbook.button(QMessageBox::Yes)->setText(trUtf8("Да"));
        msgBoxCreateWorkbook.button(QMessageBox::No)->setText(trUtf8("Нет"));
        msgBoxCreateWorkbook.button(QMessageBox::Cancel)->setText(trUtf8("Отмена"));
        int ans = msgBoxCreateWorkbook.exec();
        //            ans = QMessageBox::question(this, trUtf8("Практикум"), trUtf8("Вы хотите создать тетрадь?"),
        //                    QMessageBox::Yes | QMessageBox::No , QMessageBox::Yes);
        if (ans == QMessageBox::Yes)
        {
           
           saveCourse();
            return true;
        };
        if (ans == QMessageBox::No)
        {
           return true; 
        }
        if(ans == QMessageBox::Cancel)
        {
            return false;
        }
    }
    return true;
};
Denis Khachko's avatar
Denis Khachko committed
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
void MainWindowTask::returnTested()
{
   interface->setPreProgram(QVariant(course->getUserTestedText(curTaskIdx.internalId())));
};
QString MainWindowTask::loadTestAlg(QString file_name)
{
    if(file_name.isEmpty())return "";
    QFile file(curDir+"/"+file_name);
    if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {

        QMessageBox::about(NULL, trUtf8("Ошибка"),trUtf8("Невозможно открыть ")+curDir+"/"+file_name);
        return "";
    };
    QTextStream ts(&file);
    ts.setCodec("UTF-16LE");
    QString testalg= ts.readAll();
    file.close();

    qDebug()<<"Test alg"<<testalg;
    return testalg;
}
void MainWindowTask::aboutToQuit()
{
  close();
};
void MainWindowTask:: customContextMenuRequested(QPoint  pos)
{
editRoot->hide();
    if(!isTeacher)return;

    curTaskIdx=ui->treeView->currentIndex();
    if(curTaskIdx.internalId()==0)
    {setEditTaskEnabled(false);
        ui->actionEdit->setEnabled(true);
        ui->addDeep->setEnabled(true);
    }else setEditTaskEnabled(true);
        if(!baseKursFile.isReadable())
    {
            return;
        };
    pos.setY(pos.y()+ui->mainToolBar->height());
    customMenu.move(pos+this->pos()+ui->centralWidget->pos());
    customMenu.show();
  qDebug()<<"Menu Request!!!";
};
void MainWindowTask::addTask()
{
    qDebug()<<"Add task";
       QModelIndex par=curTaskIdx.parent();
course->addSiblingTask(curTaskIdx.internalId());
ui->treeView->collapse(par);
ui->treeView->expand(par);
};
void MainWindowTask::addDeepTask(){
    qDebug()<<"Add deep task";
       QModelIndex par=curTaskIdx.parent();
course->addDeepTask(curTaskIdx.internalId());
ui->treeView->collapse(par);
ui->treeView->expand(par);
saveBaseKurs();
if(curTaskIdx.internalId()==0)
 {
      loadCourseData(baseKursFile.absoluteFilePath());
 }
};
void MainWindowTask::deleteTask()
{
    QModelIndex par=curTaskIdx.parent();
course->removeNode(curTaskIdx.internalId());
ui->treeView->collapse(par);
ui->treeView->expand(par);
};

void MainWindowTask::saveKurs()
{
    qDebug()<<"Save Kurs teacher";
    QFile cursKursFile("../../test.kurs.xml");
    if  (!cursKursFile.open(QIODevice::WriteOnly))
    {
    QMessageBox::information( 0, "", trUtf8("Ошибка записи: ") + cursKursFile.fileName(), 0,0,0);
    return;
    };

    cursKursFile.write(course->document()->toByteArray());
    cursKursFile.close();
    ui->actionEdit->setEnabled(true);
};
void MainWindowTask::saveBaseKurs()
{
    QFile cursKursFile(baseKursFile.absoluteFilePath());
    if  (!cursKursFile.open(QIODevice::WriteOnly))
    {
    QMessageBox::information( 0, "", trUtf8("Ошибка записи: ") + cursKursFile.fileName(), 0,0,0);
    return;
    };

    cursKursFile.write(course->document()->toByteArray());
    cursKursFile.close();
}

void MainWindowTask::saveKursAs()
{
    QString dir=curDir;
    QDir chD(curDir);
    if(!chD.exists())dir=QDir::homePath ();
     QFileDialog dialog(this,trUtf8("Сохранить файл курса"),dir, "(*.kurs.xml )");
     dialog.setAcceptMode(QFileDialog::AcceptSave);

     if(!dialog.exec())return;
     QFileInfo fi(dialog.selectedFiles().first());
     baseKursFile=fi;






     saveBaseKurs();

;
};
void MainWindowTask:: setTeacher(bool mode)
1045
{
Denis Khachko's avatar
Denis Khachko committed
1046 1047 1048 1049 1050
    ui->actionup->setVisible(false);
     ui->actionDown->setVisible(false);
    isTeacher=mode;};
void MainWindowTask::editTask()
{
Denis Khachko's avatar
Denis Khachko committed
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
//if(curTaskIdx.internalId()==0)//ROOT
//    {
//
//    QRect rect=ui->treeView->visualRect(curTaskIdx);
//    editRoot->resize(rect.width(),rect.height());
//     editRoot->setText(course->rootText());
//    editRoot->move(rect.topLeft());
//    editRoot->show();
//    return;
//     };
//    QModelIndex par=curTaskIdx.parent();
//
//editDialog->setTitle(course->getTitle(curTaskIdx.internalId()));
//editDialog->setDesc(course->getTaskText(curTaskIdx));
//editDialog->setProgram(course->progFile(curTaskIdx.internalId()));
//QStringList isps=course->Modules(curTaskIdx.internalId());
//
//if(isps.count()>0)editDialog->setUseIsps(isps.first());
//   else editDialog->setUseIsps("");
//
//if(course->Modules(curTaskIdx.internalId()).count()>0)editDialog->setEnvs(course->Fields(curTaskIdx.internalId(),isps.first()));
// else editDialog->setEnvs(QStringList());
//editDialog->setCurDir(curDir);
// if(editDialog->exec ())
// {
//  course->setUserText(curTaskIdx.internalId(),"");
//  course->setTitle(curTaskIdx.internalId(),editDialog->getTitle());
//  course->setDesc(curTaskIdx.internalId(),editDialog->getDesc());
//  qDebug()<<"Desc"<<editDialog->getDesc();
//  course->setProgram(curTaskIdx.internalId(),editDialog->getProgram());
//  qDebug()<<"EDIT ISPS"<<editDialog->getUseIsps();
//
//
//  course->setIsps(curTaskIdx,editDialog->getUseIsps());
//  qDebug()<<"PRG"<<editDialog->getProgram();
//  if(course->Modules(curTaskIdx.internalId()).count()>0)course->setIspEnvs(curTaskIdx,course->Modules(curTaskIdx.internalId()).first(),editDialog->getEnvs());
// showText(curTaskIdx);
//  ui->treeView->collapse(par);
//  ui->treeView->expand(par);
//  qDebug()<<"Set task isps:"<<course->Modules(curTaskIdx.internalId());
//  qDebug()<<"EDIT DIALOG EXEC OK";
//  saveBaseKurs();
//  resetTask();
// };
//
Denis Khachko's avatar
Denis Khachko committed
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112
};

void MainWindowTask::setEditTaskEnabled(bool flag)
{
   // ui->actionEdit->setEnabled(flag);
    ui->actionup->setEnabled(flag);
    ui->actionDown->setEnabled(flag);

    ui->actionSaveKas->setEnabled(flag);
    ui->actionAdd->setEnabled(flag);
    ui->actionRemove->setEnabled(flag);
    ui->addDeep->setEnabled(flag);
};

void MainWindowTask::newKurs()
{

Denis Khachko's avatar
Denis Khachko committed
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
// if(newDialog->exec())
// {
//    QFile newKurs(newDialog->fileName());
//
//    if  (!newKurs.open(QIODevice::WriteOnly))
//    {
//    QMessageBox::information( 0, "", trUtf8("Ошибка записи: ") + newKurs.fileName(), 0,0,0);
//    return;
//    };
//    QString toWr="<?xml version='1.0' encoding='UTF-8'?>\n";
//    newKurs.write(toWr.toUtf8());
//    toWr="<KURS xml:id=\"0\" xml:name=\""+newDialog->name()+"\">\n";
//    newKurs.write(toWr.toUtf8());
//
//    toWr=QString::fromUtf8("<T xml:id=\"1\" xml:name=\"Новое задание\">\n<DESC>Нет Описания</DESC>\n<CS>Кумир</CS>\n <ISP xml:ispname=\"Robot\">\n</ISP>\n<READY>false</READY>\n</T>\n");
//    newKurs.write(toWr.toUtf8());
//
//    toWr="</KURS>\n";
//    newKurs.write(toWr.toUtf8());
//    newKurs.close();
//    loadCourseData(newKurs.fileName());
//    baseKursFile=QFileInfo(newKurs);
//    curDir=baseKursFile.absolutePath();
//    ui->actionEdit->setEnabled(true);
// }
Denis Khachko's avatar
Denis Khachko committed
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155

};
  void  MainWindowTask::createMoveMenu()
{

  }
void MainWindowTask::endRootEdit()
{
    course->setRootText(editRoot->text());
   editRoot->hide();
}
 void MainWindowTask::cancelRootEdit()
 {  editRoot->hide();
 };
void MainWindowTask::lockCheck()
{
    ui->checkTask->setDisabled(true);
}