Хранилища Subversion OpenInventory

Редакция

Редакция 161 | Редакция 167 | К новейшей редакции | Весь файл | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS

Редакция 161 Редакция 165
Строка 275... Строка 275...
275
275
276
   CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent)
276
   CPictureDelegate::CPictureDelegate( QObject * parent ) : QItemDelegate(parent)
277
   {
277
   {
278
   }
278
   }
279
279
-
 
280
-
 
281
-
 
282
-
 
283
-
 
284
   QWidget *CPictureDelegate::createEditor(QWidget *parent,
-
 
285
       const QStyleOptionViewItem &/* option */,
-
 
286
       const QModelIndex &/* index */) const
-
 
287
   {
-
 
288
-
 
289
       IconForm *editor = new IconForm(parent);
-
 
290
       return editor;
-
 
291
-
 
292
   }
-
 
293
-
 
294
-
 
295
-
 
296
-
 
297
   void CPictureDelegate::setEditorData(QWidget *editor,
-
 
298
                                       const QModelIndex &index) const
-
 
299
   {
-
 
300
-
 
301
-
 
302
       const QAbstractItemModel * model = index.model();
-
 
303
       IconForm *icnFrm = static_cast<IconForm*>(editor);
-
 
304
       QVariant currentImage = model->data(index,0);
-
 
305
       QByteArray bytes = currentImage.toByteArray();
-
 
306
       if (currentImage.isValid()) {
-
 
307
            m_pxPicture.loadFromData(bytes);
-
 
308
       }
-
 
309
       else {
-
 
310
           //QItemDelegate::paint(painter, option, index);
-
 
311
       return;
-
 
312
       }
-
 
313
       icnFrm->setPixmap(m_pxPicture);
-
 
314
   }
-
 
315
-
 
316
-
 
317
-
 
318
-
 
319
   void CPictureDelegate::setModelData(
-
 
320
               QWidget *editor,
-
 
321
               QAbstractItemModel *model,
-
 
322
               const QModelIndex& index) const {
-
 
323
       IconForm *icnFrm = static_cast<IconForm*>(editor);
-
 
324
       m_pxPicture = icnFrm->pixmap();
-
 
325
       QImage currentImage = m_pxPicture.toImage();
-
 
326
          QByteArray bytes;
-
 
327
          QBuffer buffer(&bytes);
-
 
328
          buffer.open(QIODevice::WriteOnly);
-
 
329
          currentImage.save(&buffer, "PNG");
-
 
330
-
 
331
-
 
332
-
 
333
-
 
334
         model->setData(index, QVariant (bytes), Qt::EditRole);
-
 
335
-
 
336
     //    int widht = m_pxPicture.width();
-
 
337
     //    int heigh =  m_pxPicture.height();
-
 
338
     //    tblView->setRowHeight(index.row(), heigh + 10);
-
 
339
         // model->submitAll();
-
 
340
-
 
341
-
 
342
-
 
343
-
 
344
      // model->setData(index, value);
-
 
345
   }
-
 
346
-
 
347
-
 
348
-
 
349
   void CPictureDelegate::updateEditorGeometry(
-
 
350
               QWidget *editor,
-
 
351
               const QStyleOptionViewItem &option,
-
 
352
               const QModelIndex& /* index */) const {
-
 
353
-
 
354
-
 
355
   //    QRect r(option.rect.x() + option.rect.width()/2 - 7, option.rect.y() + option.rect.height()/2 - 7, 150, 100);
-
 
356
     //      editor->setGeometry(r);
-
 
357
-
 
358
        editor->setGeometry(option.rect);
-
 
359
   }
-
 
360
-
 
361
-
 
362
-
 
363
280
   void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
364
   void CPictureDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
281
   {
365
   {
282
           m_pxPicture.fill( QColor(Qt::white) );
-
 
283
366
284
           const QAbstractItemModel * model = index.model();
-
 
285
           QString sFileName = model->data( index, Qt::DisplayRole ).toString();
-
 
286
367
-
 
368
          m_pxPicture.fill( QColor(Qt::white) );
-
 
369
-
 
370
          const QAbstractItemModel * model = index.model();
-
 
371
          QString sFileName = model->data( index, Qt::DisplayRole ).toString();
-
 
372
287
           QVariant currentImage = model->data(index,0);
373
          QVariant currentImage = model->data(index,0);
288
374
289
375
290
           QByteArray bytes = currentImage.toByteArray();
376
           QByteArray bytes = currentImage.toByteArray();
291
     //       QImage image;
377
     //       QImage image;
292
     //       image.loadFromData(bytes);
378
     //       image.loadFromData(bytes);
293
379
294
380
295
           if (currentImage.isValid()) {
381
           if (currentImage.isValid()) {
296
                m_pxPicture.loadFromData(bytes);
382
                m_pxPicture.loadFromData(bytes);
-
 
383
297
           }
384
           }
298
           else {
385
           else {
299
               //QItemDelegate::paint(painter, option, index);
386
               //QItemDelegate::paint(painter, option, index);
300
           return;
387
           return;
301
           }
388
           }
302
389
303
390
-
 
391
-
 
392
-
 
393
304
           /*
394
           /*
305

395

306
           if ( !sFileName.isEmpty() )
396
           if ( !sFileName.isEmpty() )
307
                   m_pxPicture.load( sFileName );
397
                   m_pxPicture.load( sFileName );
308
           else {
398
           else {
Строка 315... Строка 405...
315
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
405
           QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ?
316
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
406
                                                             ((option.state & QStyle::State_Active) ? QPalette::Normal : QPalette::Inactive ) :
317
                                                             QPalette::Disabled;
407
                                                             QPalette::Disabled;
318
408
319
            if (option.state & QStyle::State_Selected)
409
            if (option.state & QStyle::State_Selected)
-
 
410
-
 
411
320
                    painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
412
                painter->fillRect(option.rect, option.palette.color(cg, QPalette::Highlight));
321
413
322
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
414
           int nX = option.rect.x() + ( ( option.rect.width() - m_pxPicture.rect().width() ) / 2 );
323
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
415
           int nY = option.rect.y() + ( ( option.rect.height() - m_pxPicture.rect().height() ) / 2 );
324
           painter->drawPixmap( nX, nY, m_pxPicture );
416
           painter->drawPixmap( nX, nY, m_pxPicture );
325
417
326
418
327
       ////    drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
419
       //    drawFocus(painter, option, option.rect.adjusted(0, 0, -1, -1)); // since we draw the grid ourselves
328
420
329
           /*
421
           /*
330
           QPen pen = painter->pen();
422
           QPen pen = painter->pen();
331
           painter->setPen(option.palette.color(QPalette::Mid));
423
           painter->setPen(option.palette.color(QPalette::Mid));
332
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
424
           painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
333
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
425
           painter->drawLine(option.rect.topRight(), option.rect.bottomRight());
334
           painter->setPen(pen);
426
           painter->setPen(pen);
335
   */
427
   */
336
   }
428
}
337
429
338
430
-
 
431
   void CPictureDelegate::setTableView(QTableView* table){
-
 
432
       tblView = table;
-
 
433
   }