Esempio n. 1
0
bool QPlatformPixmap::fromData(const uchar *buf, uint len, const char *format, Qt::ImageConversionFlags flags)
{
    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buf), len);
    QBuffer b(&a);
    b.open(QIODevice::ReadOnly);
    QImage image = QImageReader(&b, format).read();
    if (image.isNull())
        return false;
    fromImage(makeBitmapCompliantIfNeeded(this, image, flags), flags);
    return !isNull();
}
Esempio n. 2
0
bool QVGPixmapData::fromFile(const QString &filename, const char *format,
                          Qt::ImageConversionFlags flags)
{
    QImage image = QImageReader(filename, format).read();
    if (image.isNull())
        return false;

    createPixmapForImage(image, flags, true);

    return !isNull();
}
Esempio n. 3
0
// really generate the background pixmap according to current settings and apply it.
void DesktopWindow::updateWallpaper() {
  // reset the brush
  // QPalette palette(listView_->palette());
  QPalette palette(Fm::FolderView::palette());

  if(wallpaperMode_ == WallpaperNone) { // use background color only
    palette.setBrush(QPalette::Base, bgColor_);
  }
  else { // use wallpaper
    QPixmap pixmap;
    QImage image;
    if(wallpaperMode_ == WallpaperTile) { // use the original size
      image = QImage(wallpaperFile_);
      pixmap = QPixmap::fromImage(image);
    }
    else if(wallpaperMode_ == WallpaperStretch) {
      image = loadWallpaperFile(size());
      pixmap = QPixmap::fromImage(image);
    }
    else { // WallpaperCenter || WallpaperFit
      if(wallpaperMode_ == WallpaperCenter) {
        image = QImage(wallpaperFile_); // load original image
      }
      else if(wallpaperMode_ == WallpaperFit) {
        // calculate the desired size
        QSize origSize = QImageReader(wallpaperFile_).size(); // get the size of the original file
        if(origSize.isValid()) {
          QSize desiredSize = origSize;
          desiredSize.scale(width(), height(), Qt::KeepAspectRatio);
          image = loadWallpaperFile(desiredSize); // load the scaled image
        }
      }
      if(!image.isNull()) {
        pixmap = QPixmap(size());
        QPainter painter(&pixmap);
        pixmap.fill(bgColor_);
        int x = (width() - image.width()) / 2;
        int y = (height() - image.height()) / 2;
        painter.drawImage(x, y, image);
      }
    }
    wallpaperPixmap_ = pixmap;
    if(!pixmap.isNull()) {
      QBrush brush(pixmap);
      palette.setBrush(QPalette::Base, brush);
    }
    else // if the image is not loaded, fallback to use background color only
      palette.setBrush(QPalette::Base, bgColor_);
  }

  //FIXME: we should set the pixmap to X11 root window?
  setPalette(palette);
}
Esempio n. 4
0
bool QRasterPlatformPixmap::fromData(const uchar *buffer, uint len, const char *format,
                      Qt::ImageConversionFlags flags)
{
    QByteArray a = QByteArray::fromRawData(reinterpret_cast<const char *>(buffer), len);
    QBuffer b(&a);
    b.open(QIODevice::ReadOnly);
    QImage image = QImageReader(&b, format).read();
    if (image.isNull())
        return false;

    createPixmapForImage(image, flags, /* inplace = */true);
    return !isNull();
}
Esempio n. 5
0
void MRichTextEdit::insertImage()
{
    QSettings s;
    QString attdir = s.value("general/filedialog-path").toString();
    QString file = QFileDialog::getOpenFileName(this,
                                                tr("Select an image"),
                                                attdir,
                                                tr("JPEG (*.jpg); GIF (*.gif); PNG (*.png); BMP (*.bmp); All (*)"));
    QImage image = QImageReader(file).read();

    //    f_textedit->dropImage(image, QFileInfo(file).suffix().toUpper().toAscii().data() );

}
Esempio n. 6
0
/*Fonction qui liste les images contenue dans un dossier et en créer un QStringList
 */
QStringList mainWindow::getImagesDir(QString s)
{
    QStringList ret;
    QDir dir(s);

    QStringList tmp = dir.entryList(createNameFilters(QImageReader().supportedImageFormats()), QDir::Files, QDir::Name);

    foreach(QString l, tmp)
    {
        ret << (s+"/"+l);
    }

    return ret;
}
Esempio n. 7
0
void ThemeDialog::imageChanged()
{
	if (!m_background_image->image().isEmpty()) {
		QSize image = QImageReader(m_background_image->image()).size();
		QSize desktop = QApplication::desktop()->size();
		if ((image.width() * image.height() * 4) <= (desktop.width() * desktop.height())) {
			m_background_type->setCurrentIndex(1);
		} else if (m_background_type->currentIndex() < 2) {
			m_background_type->setCurrentIndex(5);
		}
	} else {
		m_background_type->setCurrentIndex(0);
	}
	renderPreview();
}
Esempio n. 8
0
// really generate the background pixmap according to current settings and apply it.
void DesktopWindow::updateWallpaper() {
    if(wallpaperMode_ != WallpaperNone) {  // use wallpaper
        QPixmap pixmap;
        QImage image;
        if(wallpaperMode_ == WallpaperTile) { // use the original size
            image = QImage(wallpaperFile_);
            // Note: We can't use the QPainter::drawTiledPixmap(), because it doesn't tile
            // correctly for background pixmaps bigger than the current screen size.
            const QSize s = size();
            pixmap = QPixmap{s};
            QPainter painter{&pixmap};
            for (int x = 0; x < s.width(); x += image.width()) {
                for (int y = 0; y < s.height(); y += image.height()) {
                    painter.drawImage(x, y, image);
                }
            }
        }
        else if(wallpaperMode_ == WallpaperStretch) {
            image = loadWallpaperFile(size());
            pixmap = QPixmap::fromImage(image);
        }
        else { // WallpaperCenter || WallpaperFit
            if(wallpaperMode_ == WallpaperCenter) {
                image = QImage(wallpaperFile_); // load original image
            }
            else if(wallpaperMode_ == WallpaperFit || wallpaperMode_ == WallpaperZoom) {
                // calculate the desired size
                QSize origSize = QImageReader(wallpaperFile_).size(); // get the size of the original file
                if(origSize.isValid()) {
                    QSize desiredSize = origSize;
                    Qt::AspectRatioMode mode = (wallpaperMode_ == WallpaperFit ? Qt::KeepAspectRatio : Qt::KeepAspectRatioByExpanding);
                    desiredSize.scale(width(), height(), mode);
                    image = loadWallpaperFile(desiredSize); // load the scaled image
                }
            }
            if(!image.isNull()) {
                pixmap = QPixmap(size());
                QPainter painter(&pixmap);
                pixmap.fill(bgColor_);
                int x = (width() - image.width()) / 2;
                int y = (height() - image.height()) / 2;
                painter.drawImage(x, y, image);
            }
        }
        wallpaperPixmap_ = pixmap;
    }
}
Esempio n. 9
0
void ImageButton::setImage(const QString& image, const QString& path)
{
    QImageReader source(image);
    if (source.canRead()) {
        m_image = image;
        QSize size = source.size();
        if (size.width() > 100 || size.height() > 100) {
            size.scale(100, 100, Qt::KeepAspectRatio);
            source.setScaledSize(size);
        }
        setIcon(QPixmap::fromImage(source.read(), Qt::AutoColor | Qt::AvoidDither));

        m_path = (!path.isEmpty() && QImageReader(path).canRead()) ? path : QString();
        emit changed(m_path);
    } else {
        unsetImage();
    }
}
bool CImageViewerWidget::displayImage(const QString& imagePath, const QImage& image)
{
    _imageFileSize = QFileInfo(imagePath).size();
    _sourceImage = image.isNull() ? QImageReader(imagePath).read() : image;
    if (!_sourceImage.isNull())
    {
        QSize screenSize = QApplication::desktop()->availableGeometry().size() - QSize(50, 50);
        QSize windowSize = _sourceImage.size();
        if (windowSize.height() > screenSize.height() || windowSize.width() > screenSize.width())
            windowSize.scale(screenSize, Qt::KeepAspectRatio);
        resize(windowSize);
        update();

        return true;
    }
    else
    {
        QMessageBox::warning(dynamic_cast<QWidget*>(parent()), tr("Failed to load the image"), tr("Failed to load the image\n\n%1\n\nIt is inaccessible, doesn't exist or is not a supported image file.").arg(imagePath));
        return false;
    }
}
Esempio n. 11
0
bool QGLPixmapData::fromFile(const QString &filename, const char *format,
                             Qt::ImageConversionFlags flags)
{
    if (pixelType() == QPixmapData::BitmapType)
        return QPixmapData::fromFile(filename, format, flags);
    QFile file(filename);
    if (file.open(QIODevice::ReadOnly)) {
        QByteArray data = file.peek(64);
        bool alpha;
        if (m_texture.canBindCompressedTexture
                (data.constData(), data.size(), format, &alpha)) {
            resize(0, 0);
            data = file.readAll();
            file.close();
            QGLShareContextScope ctx(qt_gl_share_context());
            QSize size = m_texture.bindCompressedTexture
                (data.constData(), data.size(), format);
            if (!size.isEmpty()) {
                w = size.width();
                h = size.height();
                is_null = false;
                d = 32;
                m_hasAlpha = alpha;
                m_source = QImage();
                m_dirty = isValid();
                return true;
            }
            return false;
        }
    }

    QImage image = QImageReader(filename, format).read();
    if (image.isNull())
        return false;

    createPixmapForImage(image, flags, true);

    return !isNull();
}
Esempio n. 12
0
bool ResourceLoader::request_resource(IResourceHolder *edit, int type, const QUrl &url)
{
    assert(NULL != edit);
    const size_t MAX_DOWNLOAD_THREAD = 5; // 最大同时下载线程数

    if (type != QTextDocument::ImageResource)
        return false;

    // 首先尝试内建资源
    if (_request_builtin_resource(edit, type, url))
        return true;

    // 上锁
    const bool locked = _lock.trylock();
    if (!locked)
        return false;
    Guard<SpinLock> guard(&_lock, false);

    // 首先搜索内存
    const QString cache_path = _map_url_to_cache_path(url);
    const ResourceKey rk(type, url);
    map_t::iterator r = _resources.find(rk);
    if (r != _resources.end())
    {
        Resource& rs = r->second;
        if (rs.error) // 数据错误
            return true;

        if (!rs.res.isNull() && rs.res.isValid()) // 数据有效
        {
            _add_resource_to_edit(edit, type, url, rs.res);
            return true;
        }

        if (NULL != rs.downloader) // 数据正在下载
        {
            rs.requestList.push_back(edit);
            return true;
        }

        // 数据需要启用下载
        rs.requestList.push_back(edit);
        rs.downloader = new HttpGet(url, cache_path, this, edit->as_qobject());
        if (_downloading < MAX_DOWNLOAD_THREAD)
        {
            // 开始下载
            ++_downloading;
            rs.downloader->start_download();
        }
        else
        {
            // 达到最大同时下载数,进入等待队列
            _download_queue.push(rs.downloader);
        }
        return true;
    }

    // 再搜索缓存文件夹
    if (QFileInfo(cache_path).exists())
    {
        const QString suffix = QFileInfo(url.path()).suffix();
        const bool isgif = (suffix.toLower() == "gif");

        Resource& rs = _resources[rk];
        if (isgif)
        {
            rs.res = QVariant(cache_path);
            _add_resource_to_edit(edit, type, url, rs.res);
        }
        else
        {
            QImage img = QImageReader(cache_path).read();
            rs.res = QVariant(img);
            if (rs.res.isNull() || !rs.res.isValid())
                rs.error = true;
            else
                _add_resource_to_edit(edit, type, url, rs.res);
        }
        return true;
    }

    // 需要下载
    Resource& rs = _resources[rk];
    rs.requestList.push_back(edit);
    rs.downloader = new HttpGet(url, cache_path, this, edit->as_qobject());
    if (_downloading < MAX_DOWNLOAD_THREAD)
    {
        ++_downloading;
        rs.downloader->start_download();
    }
    else
    {
        _download_queue.push(rs.downloader);
    }
    return true;
}
Esempio n. 13
0
bool ResourceLoader::_request_builtin_resource(IResourceHolder *edit, int type, const QUrl &url)
{
    const QString url_str = url.toString();
    if (!url_str.startsWith(PROTOCAL_ORGANIC))
        return false;

    // 上锁
    Guard<SpinLock> guard(&_lock);

    // 搜索内存
    const ResourceKey rk(type, url);
    map_t::iterator r = _resources.find(rk);
    if (r != _resources.end())
    {
        Resource& rs = r->second;
        if (rs.error || rs.res.isNull() || !rs.res.isValid())
            return false;
        _add_resource_to_edit(edit, type, url, rs.res);
        return true;
    }

    // 加载资源
    PkmPlugin *plugin = dynamic_cast<PkmPlugin*>(get_plugin().pointer());
    assert(NULL != plugin);

    if (url_str.startsWith(PROTOCAL_TODOLIST))
    {
        const char *relpath = NULL;
        if (url_str == TODO_UNCHECKED_URL)
            relpath = "richtextedit/todolist/unchecked_16";
        else if (url_str == TODO_CHECKED_URL)
            relpath = "richtextedit/todolist/checked_16";
        else if (url_str == TODO_TICK_URL)
            relpath = "richtextedit/todolist/tick_16";
        else if (url_str == TODO_CROSS_URL)
            relpath = "richtextedit/todolist/cross_16";
        else if (url_str == TODO_WORKING_URL)
            relpath = "richtextedit/todolist/working_16";
        else if (url_str == TODO_WAIT_URL)
            relpath = "richtextedit/todolist/wait_16";
        else if (url_str == TODO_URGENT_URL)
            relpath = "richtextedit/todolist/urgent_16";
        else if (url_str == TODO_DELETED_URL)
            relpath = "richtextedit/todolist/deleted_16";
        else if (url_str == TODO_BUG_URL)
            relpath = "richtextedit/todolist/bug_16";

        if (NULL != relpath)
        {
            Resource& rs = _resources[rk];
            rs.res = QVariant(plugin->load_image(relpath));
            assert(!rs.res.isNull() && rs.res.isValid());
            _add_resource_to_edit(edit, type, url, rs.res);
            return true;
        }
    }
    else if (url_str.startsWith(PROTOCAL_ATTACHMENT))
    {
        DataSource *data_source = plugin->get_data_source();
        assert(NULL != data_source);

        const QString id_name = url_str.mid(::strlen(PROTOCAL_ATTACHMENT));
        QString filepath = data_source->get_attachment(id_name);
        if (!QFile::exists(filepath))
        {
            NUT_LOG_W("plugin.pkm.resourceloader", "attachment missing: %s",
                      id_name.toLocal8Bit().data());
            return false;
        }
        QImage img = QImageReader(filepath).read();
        if (img.isNull())
            return false;

        Resource& rs = _resources[rk];
        rs.res = QVariant(img);
        _add_resource_to_edit(edit, type, url, rs.res);
        return true;
    }
    return false;
}
Esempio n. 14
0
bool BE::Contacts::eventFilter(QObject *o, QEvent *e)
{
    if (o == m_ui->filter) {
        if (e->type() == QEvent::KeyPress)
        if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Down)
            m_ui->contacts->setFocus();
        return false;
    }

    if (o == m_ui->contacts) {
        if (e->type() == QEvent::KeyPress) {
            QKeyEvent *ke = static_cast<QKeyEvent*>(e);
            if (ke->key() == Qt::Key_Up && !m_ui->contacts->currentIndex().row()) {
            m_ui->filter->setFocus();
            return true;
            } else if (ke->key() == Qt::Key_Delete) {
                removeCurrentContact();
                return true;
            }
        }
        return false;
    }

    if (!m_currentContact)
        return false;
    switch (e->type()) {
    case QEvent::DragEnter:
    case QEvent::DragMove:
    case QEvent::Drop: {
        if (o != m_ui2->photo)
            return false;
        QDropEvent *de = static_cast<QDropEvent*>(e);
        if (!de->mimeData())
            return false;
        QList<QUrl> urls = de->mimeData()->urls();
        if (urls.isEmpty())
            return false;
        QUrl url = urls.first();
        if (
#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0)
                url.isLocalFile()
#else
                (url.scheme() == QLatin1String("file"))
#endif
                && QImageReader(url.path()).canRead()) {
            if (e->type() == QEvent::Drop)
                importPhoto(url.path());
            else
                de->acceptProposedAction();
        }
        return false;
    }
    case QEvent::KeyPress: {
        const int key = static_cast<QKeyEvent*>(e)->key();
        if (key == Qt::Key_Delete && o == m_ui2->photo) { // reset photo
            if (m_currentContact)
                m_currentContact->setData(QString(), Gui::AbookAddressbook::Photo);
            m_ui2->photo->setPixmap(m_incognitoPic);
        }
        else if (key == Qt::Key_Escape && o != m_ui2->photo)
        if (QLabel *l = qobject_cast<QLabel*>(o)) {
            setText(l, l->text());
            return true; // prevent closing the dialog!
        }
    }
    default:
        return false;
    }
    return false;
}
Esempio n. 15
0
CreateGroup::CreateGroup(QStringList items, QWidget *parent)
    : THWidgetBase(parent)
{
    setAttribute(Qt::WA_DeleteOnClose);
    setFixedSize(380, 250);
    setTitleBarWidth(380);
    setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
    setWindowModality(Qt::ApplicationModal);
    bar->setBarButtons(HappyTitleBar::MinButtonHint);
    bar->setBarButtons(HappyTitleBar::MaxButtonHint);
    bar->setExtraButtonVisible(false);
    bar->setBarIcon(":res/happy.png");
    bar->setBarContent(cn("创建群/讨论组"));
    connect(bar, &HappyTitleBar::signalClose, this, [=] () {
            this->close();
    });

    QVBoxLayout *v= new QVBoxLayout();
    v->setContentsMargins(0, 0, 0, 0);
    QHBoxLayout *h = new QHBoxLayout();
    h->setContentsMargins(0, 0, 0, 0);
    QVBoxLayout *v1= new QVBoxLayout();
    v1->setContentsMargins(0, 0, 0, 0);
    QVBoxLayout *v2= new QVBoxLayout();
    v2->setContentsMargins(0, 0, 0, 0);

    EmojiLabel *photo = new EmojiLabel(this);
    photo->setMoiveRes(":res/ui3/default_group_create.gif");
    photo->setMovieable(true);
    photo->setFixedSize(70, 70);
    photo->setStyleSheet(cns("QLabel{border-width:1px;border-style:solid;border-radius:3px;border-color:transparent;"
                             "background:transparent;}"
                             "QLabel:hover{border-width:1px;border-style:solid;border-radius:3px;border-color:white;}"
                             "QLabel:pressed{border-width:1px;border-style:solid;border-radius:3px;border-color:rgba(240,240,240,50);}"));
    QLabel *lbl1 = new QLabel(cn("修改群图片(点击)"), this);
    lbl1->setStyleSheet(QStringLiteral("font-family:微软雅黑;font:12px;color:white;"));
    QPushButton *pb1 = new QPushButton(cn("从表情库中选择"), this);
    pb1->setFixedWidth(120);
    v1->addWidget(photo, 8, Qt::AlignCenter);
    v1->addWidget(lbl1,  1, Qt::AlignCenter);
    v1->addWidget(pb1,  1, Qt::AlignCenter);

    QLineEdit *edit1 = new QLineEdit(this);
    edit1->setAlignment(Qt::AlignCenter);
    edit1->setFixedWidth(180);
    edit1->setPlaceholderText(cn("输入群/讨论组名称"));

    QLineEdit *edit2 = new QLineEdit(this);
    edit2->setText(cn("讨论组"));
    edit2->setReadOnly(true);
    edit2->setAlignment(Qt::AlignCenter);
    edit2->setFixedWidth(180);
    edit2->setPlaceholderText(cn("选择属性"));

    HappyTextEdit *edit3 = new HappyTextEdit(this);
    edit3->setPlaceholderText(cn("写点什么吧,这群是干啥的"));
    edit3->setFixedWidth(180);

    v2->addWidget(edit1, 1, Qt::AlignCenter);
    v2->addWidget(edit2, 1, Qt::AlignCenter);
    v2->addWidget(edit3, 8, Qt::AlignCenter);

    h->addLayout(v1, 2);
    h->addLayout(v2, 3);

    QHBoxLayout *h1 = new QHBoxLayout();
    h1->setContentsMargins(55, 0, 0, 10);
    QPushButton *selectPb = new QPushButton(cn("选择成员"), this);
    selectPb->setCheckable(true);
    selectPb->setFixedWidth(70);
    QPushButton *confirmPb = new QPushButton(cn("确定"), this);
    confirmPb->setFixedWidth(50);
    QPushButton *cancelPb = new QPushButton(cn("取消"), this);
    cancelPb->setFixedWidth(50);
    h1->addStretch(7);
    h1->addWidget(selectPb);
    h1->addWidget(confirmPb);
    h1->addWidget(cancelPb);
    h1->addStretch(1);

    v->addLayout(h, 9);
    v->addLayout(h1, 1);

    QHBoxLayout *h2 = new QHBoxLayout(this);
    h2->setContentsMargins(5, 35, 5, 10);
    CheckList *list = new CheckList(this);
    list->setFixedSize(120, 195);
    list->setVisible(false);
    h2->addLayout(v, 5);
    h2->addWidget(list, 1, Qt::AlignHCenter | Qt::AlignTop);
    h2->addSpacing(15);


    QFile file;
    file.setFileName(":res/css/lineedit.css");
    if (file.open(QIODevice::ReadOnly))
    {
        QByteArray ba = file.readAll();
        edit1->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
        edit2->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
    }
    file.close();
    file.setFileName(":res/css/button2.css");
    if (file.open(QIODevice::ReadOnly))
    {
        QByteArray ba = file.readAll();
        pb1->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
        selectPb->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
        confirmPb->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
        cancelPb->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
    }
    file.close();
    file.setFileName(":res/css/list2.css");
    if (file.open(QIODevice::ReadOnly))
    {
        QByteArray ba = file.readAll();
        list->setStyleSheet(QTextCodec::codecForLocale()->toUnicode(ba));
    }
    file.close();

    // load data
    ConfigureData *conf = ConfigureData::getInstance();
    updateColor(conf->getColorIni("color1"), conf->getColorIni("color2"));
    list->setmyuid(conf->getUuid());
    list->addCheckItems(items);

    connect(confirmPb, &QPushButton::clicked, this, [=] () {
        QString name = edit1->text();
        if (name.trimmed().isEmpty())
        {
            MsgBox::ShowMsgBox(cn("错误"),
                               cn("不能使用空的名称"),
                               cn("确定"));
            return;
        }
        QString attr = edit2->text();
        QString des = edit3->toPlainText();
        if (des.trimmed().isEmpty())
        {
            int rlt = MsgBox::ShowMsgBox(cn("提示"),
                               cn("真的不写点什么?"),
                               cn("不写了"), cn("那写点"));
            if (rlt != 0)
                return;
        }
        QString uids = list->checkedids();
        if (uids.split(";").size() <= 1)
        {
            int rlt = MsgBox::ShowMsgBox(cn("提示"),
                               cn("这个组里面只有你一个人\n"
                                  "确定创建这个寂寞的群组么?"),
                               cn("确定"), cn("去选人"));
            if (rlt == 1)
            {
                selectPb->setChecked(true);
                return;
            }

        }
        // check image
        QString newPhotoName = photo->ImagePath();
        QString path = GetWorkPath() + "/face";
        if (QDir().mkpath(path))
        {
            QFile file;
            file.setFileName(newPhotoName);
            if (file.exists())
            {
                QString temp = path + "/" + QFileInfo(newPhotoName).fileName();
                if (QFile::exists(temp))
                {
                    newPhotoName = temp;
                }
                else
                {
                    bool b = file.copy(temp);
                    if (b)
                        newPhotoName = temp;
                }
            }
            file.close();
        }

        // 创建数据
        GroupData gd;
        gd.setName(name);
        gd.setAttr(attr);
        gd.setGroupdescribe(des);
        gd.setPhoto(newPhotoName);
        gd.setGroupmember(uids);
        gd.setUid(getUuid());
        gd.setDeleteable(true);
        gd.setEditable(true);
        QDateTime dt = QDateTime::currentDateTime();
        gd.setCreationtime(dt.toString("yyyy-MM-dd hh:mm:ss"));
        gd.setUpdatetime(dt.toTime_t());
        gd.setCreator(conf->getIni("nickname"));
        gd.setPort(qrand() % 10000 + 20000);
        gd.setNetmask(createNetmask());
        emit confrimCreate(gd);
        close();
    });
    connect(cancelPb, &QPushButton::clicked, this, [=] () {
        emit bar->signalClose();
    });

    connect(selectPb, &QPushButton::toggled, this, [=] (bool b) {
        if (b)
        {
            setFixedWidth(480);
            setTitleBarWidth(480);
        }
        else
        {
            setFixedWidth(380);
            setTitleBarWidth(380);
        }
        list->setVisible(b);
    });

    connect(this, &CreateGroup::updateItems,
            list, &CheckList::addCheckItems);

    connect(pb1, &QPushButton::clicked, this, [=] () {
        EmotionsBox *box = EmotionsBox::GetInstance();
        box->show();
        box->activateWindow();
        QPoint p = QCursor::pos();
        box->move(p.x() - box->width() / 2, p.y() - 20 - box->height());
        connect(box, &EmotionsBox::select, this, [=] (QString str) {
            photo->setMoiveRes(str);
        });
        connect(box, &EmotionsBox::signalHide, this, [=] () {
            disconnect(box, &EmotionsBox::signalHide, 0, 0);
            disconnect(box, &EmotionsBox::select, 0, 0);
        });
    });
    connect(photo, &EmojiLabel::clicked,
            this, [=] () {
        QString filter = cns("图片资源(*.jpg *.gif *.png*.bmp);;全部文件(*.*)");
        QString path = QFileDialog::getOpenFileName(this, QStringLiteral("选择图片"),
                                                    ".", filter);
        if (!QFileInfo(path).isFile() && !QImageReader(path).canRead())
        {
            MsgBox::ShowMsgBox(cn("错误"),
                               cn("不是有效的文件"),
                               cn("确定"));
            return;
        }
        photo->setMoiveRes(path);
    });
}
Esempio n. 16
0
QSize PositionDelegate::sizeHint(const QStyleOptionViewItem & /* option */, const QModelIndex & /* index */) const
{
  return QImageReader(":/images/centered_maxpect").size() + QSize(5,5);
}