You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

searchfellowdlg.cpp 1.5 kB

8 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "searchfellowdlg.h"
  2. #include "ui_searchfellowdlg.h"
  3. SearchFellowDlg::SearchFellowDlg(QWidget *parent) :
  4. QDialog(parent),
  5. ui(new Ui::SearchFellowDlg)
  6. {
  7. ui->setupUi(this);
  8. connect(ui->searchEdit, SIGNAL(textChanged(QString)), this, SLOT(search(QString)));
  9. connect(ui->cancelBtn, SIGNAL(pressed()), this, SLOT(hide()));
  10. connect(ui->okBtn, SIGNAL(pressed()), this, SLOT(searchDone()));
  11. connect(ui->resultListWidget, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(searchDone()));
  12. }
  13. SearchFellowDlg::~SearchFellowDlg()
  14. {
  15. delete ui;
  16. }
  17. void SearchFellowDlg::setSearchDriver(function<vector<const Fellow*>(const QString &)> driver)
  18. {
  19. mSearchDriver = driver;
  20. }
  21. void SearchFellowDlg::search(const QString &text)
  22. {
  23. if (mSearchDriver)
  24. {
  25. mCurResult = mSearchDriver(text);
  26. ui->resultListWidget->clear();
  27. for (const Fellow* fellow : mCurResult)
  28. ui->resultListWidget->addItem(QString(fellow->toString().c_str()));
  29. if (mCurResult.size() > 0)
  30. ui->resultListWidget->setCurrentRow(0);
  31. ui->okBtn->setEnabled(mCurResult.size()>0);
  32. }
  33. }
  34. void SearchFellowDlg::searchDone()
  35. {
  36. auto row = ui->resultListWidget->currentRow();
  37. if (row >= 0)
  38. {
  39. emit onFellowSelected(mCurResult[row]);
  40. hide();
  41. }
  42. }
  43. void SearchFellowDlg::showEvent(QShowEvent *)
  44. {
  45. loadAllFellows();
  46. }
  47. void SearchFellowDlg::loadAllFellows()
  48. {
  49. search("");//search 空字符串将获得所有好友
  50. }

mac下的“飞秋”大多数只是飞鸽传书协议,而且未发现令人满意的开源项目,所以基于c++与qt实现了基础的飞秋协议。

Contributors (1)